C :: Trying To Scanf A Char And Code Just Jump Over It

Jan 25, 2014

I'm doing a code to calculate the final grade of students. This is a work for college, and I need to keep this structure.

My problem is that last scanf, it is ignored when I compile the code. It "works" if I try to scan a string, float or int.

Code:

#include <stdio.h>
#include <stdlib.h>
void nfinal(float NOTA1,float NOTA2,float NOTA3,char MEDIA){
int NOTA;
if(MEDIA=='A'){
NOTA=(NOTA1+NOTA2+NOTA3)/3;

[Code]....

View 3 Replies


ADVERTISEMENT

C :: How To Scanf To Integer Or Char

Feb 6, 2014

I have to make a program for school to evalute poker hand.I am not asking about the logic of the program,I am asking because I have to take the input from the console,five lines which can be the cards 2,3,4..10 and the problem is with J,Q,K,A ,because I dont know how to tell scanf to expect integer or char ? If I type J,Q,K,A the program crash ,

View 1 Replies View Related

C :: Getting Char As Input By Scanf

Mar 31, 2014

In GCC v4.6, I am encountering a strange problem. If I try to get a character input and a int input like this:

Code:

int main()
{
int a;
char b;
scanf("%d",&a);
scanf("%c",&b);
}

the compiled program asks for input only one time. On the other hand, if I do the char scanf earlier like this:

Code:

int main()
{
int a;
char b;
scanf("%c",&b);
scanf("%d",&a);
}

it asks for input twice.

View 6 Replies View Related

C++ :: Keep Getting Wrong Results With Char And Scanf

Nov 12, 2013

Code:
#include <stdio.h>
int main(){
unsigned char x, y=10;
scanf ("%c", &x);

[Code] ....

If I take out scanf and assign x a value then it works, but if I enter, for example, 10 into scanf it comes up as 234 rather than 100.

View 13 Replies View Related

C++ :: Why Cannot Jump Out Of For Loop

Jun 6, 2013

I got code like this:

#include <iostream>
#include <vector>
using namespace std;
const long nx(3);
const long ny(3);
const long seal(-1);
long TotP(0);
class pore {

[Code]...

I can print out all those TotP, but cannot get Finish loop print out, why? If I put any statement below, which seems won't be executed, it is like it never jump out from the loop and die inside.

View 9 Replies View Related

C++ :: Code Only Prints Out First Char Of Each String

Feb 27, 2012

I have the following code that prints out only the first char of each string. Why does it not print out the entire unsgined char* ?

Code:
#include <iostream>
#include <vector>
using namespace std;
void PrintVector(vector<unsigned char*>& data) {
for(size_t i = 0; i < data.size(); i++)

[Code] .....

View 5 Replies View Related

C++ :: Increase Char Code Doesn't Work

Jun 11, 2014

Code:

#include <iostream>
using namespace std;
int main () {
char character = 'a';

[Code] .....

the point of this code is to increase character by 1 (so from a to b in this case).

The line highligted in red is the line that the system is rejecting at the moment (but there may be other issues). why it is invalid?

View 5 Replies View Related

C++ :: Debugging Code (Displaying Char String Per Character)

Jul 16, 2014

I've tried a bunch of alternative methods to prevent an assertion error. "not understanding" the bug and why I'm getting it are relevant here, not proper, (or more appropriate), coding methods. I would write it in another way to prevent the error, I simply want to understand what is happening during run-time that causes the situation.What is the bug?

---------------------------------------
[assertion error]
[expression _block_type_is_valid(phead->nBlockUse)]
--------------------------------

Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Enter your name : ";
string Name;

[code]...

View 1 Replies View Related

C++ :: Translate Char Array From (Russian Code) To Unicode?

Feb 10, 2012

How translate char array from "MS-DOS Codepage 866" (Russian code) to Unicode?

View 3 Replies View Related

C# :: How To Jump From One TextBox To Next When Press Enter Key

Apr 13, 2014

How can i jump from textBox to next texBox when i press enterKey in c# , what i the event for that .....

View 2 Replies View Related

C/C++ :: Jump Table Instead Of Switch Cases?

Aug 14, 2012

I have an issue with switch case. There are about 32 cases to be handled in switch. each case just assigns a hexadecimal to a local variable.

#define ADFV 0x0301
Switch(error_index)
{
case 1:
var = ADFV;
........
}
}

can i use jump table for above issue to reduce the code size.

View 4 Replies View Related

C/C++ :: Conditional Jump Or Move Depends On Uninitialized Value(s)

Nov 24, 2014

I am getting this message from Valgrind, As far as I can see what it points to is initialized. The memory it is referring to is freed in unload and I was not getting this error until after I added the check function. Valgrind was happy. Here is the code and the error message from Valgrind. I am trying to create a spell checker for an assignment for a online class I am taking. I just want to get this table working correctly before I add it to the rest of the program. The code seems to run fine but I have come to see that dos not mean much in C.

#include "hashTable.h"
#include <stdbool.h>
table_node hash_table[TABLE_LENGTH];
bool loaded = true;
//assigning letters a-z to table nodes for buckets
void key_hash_t( )

[Code] ....

Valgrind error:

arortell@gentoo ~/Development/Projects/C_Projects/Data_Structures/HashTable $ valgrind --leak-check=full --track-origins=yes ./hashTable
==11360== Memcheck, a memory error detector
==11360== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==11360== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==11360== Command: ./hashTable

[Code] ....

View 10 Replies View Related

C++ :: Conditional Jump Depends On Uninitialized Value Valgrind

Jan 10, 2013

I have airport class which should navigate planes, in its list to runways, with method move, theres a method prepare which changes the direction of flight to all planes, always before move is called, move just increments decrement x and y of plane in its list. But after calling two times in row airport->move(), I get screwed and I really dont know wheres the problem. Have I badly initiazed something? Iterator gets invalidated.

Valgrind Stacktrace
Conditional jump or move depends on uninitialised value(s)
==26207== at 0x409601: plane::move() (in /home/xnovak11/Downloads/airport/main)
==26207== by 0x401FBD: airport::move() (in /home/xnovak11/Downloads/airport/main)
==26207== by 0x405FE1: io::start(std::istream&, std:stream&, std:stream&) (in /home/xnovak11/Downloads/airport/main)

This is how I add planes into list in airport

Code:
list<plane*> planes;
list<plane*>::const_iterator planeIterator;
list<plane*>::iterator planeIteratorMoj;
bool airport::addPlane(const plane& p) {

[Code] .....

This is the method where it fails. When I call it once, no problem, after second call I get instead of normal number in cout<<after move<< s1 i get like 8795456 ....

Code:
void airport::move() {
for(planeIteratorMoj = planes.begin(); planeIteratorMoj!= planes.end(); planeIteratorMoj++) {
plane * p1 = (*planeIteratorMoj);
int s,w;
p1->getPosition(s,w);

[Code] .....

View 3 Replies View Related

C :: How To Put Value From Scanf Into Array

May 2, 2013

Code:

#include<stdio.h>
#include<windows.h>
int nr, i, array_new[10],n=0;
main(){
printf ("Insert number: ");
scanf ("%d", &nr);

[Code]...

I need put value from scanf into array. How make this: array_new[nr]?

View 8 Replies View Related

C :: Using Scanf In If / Else Statement

Aug 7, 2013

When I do this:

Code:

#include <stdio.h>
#include <stdlib.h>
int main () {
int guess ;
int number = 5 ;

[Code] .....

But when I do this:

Code:
#include <stdio.h>
#include <stdlib.h>
int main () {
int guess ;
int number = 5 ;

[Code] ....

Why does the compiler say that there is an else without a previous if ??? ... Does this mean that I cannot use "scanf" in an if/else statement?

View 2 Replies View Related

C :: Get Rid Of Space / Use Scanf Or Getchar

Sep 24, 2014

I want the user to be able to enter a command then a character, like for example: push r....I want the command to be stored in the array command, and the character to be stored in the variable c.

Now I wonder what the best way to get rid of the space is, using scanf or getchar (see below for code, only thing that I changed between the 2 versions is the statement before the comment "get rid of space")? Or maybe it doesnt matter?

Code:

include <stdio.h>
#define MAX 200
void push(char c); // Puts a new element last in queue
char pop(void); // Gets the first element in queue
static char s[MAX];
}

[code]....

View 6 Replies View Related

C :: How To Write Scanf With Right Parameters

Jun 30, 2013

How can i upgrade my program I want to input a octal and binary number and convert them in base 2, 8, 10, 16..

how can I write the scanf with the right parameter in it??

Code:
scanf ("%x",&i); Code: #include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main() {
int i;
char buffer [33];

[Code] .....

View 5 Replies View Related

C :: Scanf / Fgets Without Echo

Aug 31, 2014

I am trying to write a terminal-like chat application in Linux. I would like to use a FIFO queue to print out the messages in terminal. The queue would be populated from 2 sources- stdin and messages sent from the other user over TCP. I have meet an obstacle that I cannot handle...

Lets say I would like to take user input using fgets and put it into a buffer. Then queue it if the buffer is not empty or print if it is. The problem is that when I use fgets or scanf, my input is instantly printed to the terminal..If i do:

Code:

fgets(message, 100, stdin); printf

("%s", message The string under message is printed twice :|. Is there a way to prevent this?

View 5 Replies View Related

C :: Scanf With Stopping Condition

Mar 22, 2013

I wanted to input some numbers with scanf function, i can enter some numbers and if I input -1 to the scanf, the input must end. And the scanf function has limited input, the max that I can input is 40 numbers.example if enter 1 2 4 6 5 4 -1 the scanf function will ended and the result will be appear.I wanted to know how the scanf function is like that would be best for this problem, Code: scanf("%d", &n); the result if I input those number will be like

|
||
||||
||||||
|||||
||||

View 3 Replies View Related

C :: How To Scanf Inputs Into Array

Nov 23, 2014

I don't know how many numbers will be the input only that its going to be up to 10000. EOF should be active. I tried it like this:

Code:

int i = 0;
int del[10000]
while (scanf("%d",del[i])!=EOF)
{
i++;
}

But it seems the value of i doesn't increment, could you provide some tips on how to scanf the inputs into an array if I don't know how many numbers will I have?

View 7 Replies View Related

C :: Scanf Is Skipped In Run Window

Jul 11, 2014

when i run it , it skips scanf and not allowing user to enter input.tried adding getchar(), fflush but nothing worked for me.
//file name : sort_array_of_structure.c

Code:

/*Write a program to accept records of the different states using array of structures. The structure should contain char state, population, literacy rate, and income. Display the state whose literacy rate is highest and whose income is highest.*/

#include <stdio.h>
#define M 50
struct state
{
char name[50];
long int population;
float literacyRate;
float income;
}

[code]....

View 3 Replies View Related

C/C++ :: Checking For A Space In Scanf

Jan 23, 2014

I have created a prompt which prompts the user for an integer and I have set up a loop to check for if it is an integer or not. My "bug" is that a user can enter an "integer" and "space" and "enter" and it does not give any error and assumes that "All is FINE!". I have gotten the value from the ascii table of 'SPACE' and put it as a check in my parameter of while, but it does not work.

Here is my code:

int x, y, boolean, i;
char buff[256];
printf("Enter the first integer value: ");
scanf("%s", buff);
i = 0;
boolean = 0; //initializing our boolean var that will eventually decide if we have an error or not

[code]....

View 4 Replies View Related

C++ :: How To Flush Scanf Buffer In C

Oct 10, 2014

I am writing a program and am asking the user to enter a number between 1-12.

If they do not, they will be promoted over and over again to enter a number between 1-12.

However, if the user enters a letter or anything else scanf seems to stop working and then my loop goes out of control.

View 2 Replies View Related

C++ :: Input Using Printf / Scanf

Oct 28, 2014

How to store the value in this case.. The topic is called "limited summation".. The following is the guideline for this problem:

Write a program in a folder called "sum" with a source file of main.cpp that does the following:

•prompt a user to enter a maximum number of entries, make the prompt "max # entries"

•prompt a user to enter a threshold sum, make the prompt "threshold"

•using error checking logic, let a user enter base-10 signed numbers until at least one of the following conditions is true:

or the maximum number of entries is reached
or the sum of entered numbers has reached (>=) the threshold

•print the sum of all the entries, just the number and a linefeed at the end of the line

Error checking means entries that are not numbers are detected and ignored. You are to use printf and scanf in this assignment (no cin or cout).

View 3 Replies View Related

C :: Scanf Input By The User Into Function

Apr 19, 2013

I tried to scanf the input by the user into the function but it does not read my input. Read on one of the thread, it said that to scanf a input into a double, need to use %1f instead to %d (which normally used. I tried changing it to %1f and it still did not work.

Code:
#include <stdio.h>
#include <math.h>
/* function main begins program execution */
int main( void )
{
double amount; /* amount on deposit */

[Code] ....

View 2 Replies View Related

C :: How To Scanf Global Variable Outside The Main

Sep 7, 2013

The problem that I want to make an array " vertextDegree [nbColours] " with " nbColours " elements in it ,but the "nbColours" unknown and I have to get it get it from a file .

Code:

int nbEdges,nbVetices, nbColours ;
typedef struct st_graphVertex {
int index;
int colour;
int val ;
int vertexDegree[nbColours]; // it won't work because nbColours unknown
// here and I want get it from file in the main
struct st_graphVertex *next;
t_edgeList *out;
}t_grapheVertex;

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved