January 14th, 2013, 06:57 AM
C programing help
im a real beginner in c programing,
and im trying to sum two numbers and im doin it with switch
although i dont know how to use it.
i know i can do it some other way,
and when im runing this prog it showing some wrong num,
and i cant give data to scanf("%d",&b);
but just wandering so plzzz help
thanks in advance
printf("\t\t\t this is calculator program \n\n\n\n");
printf("enter 1st num: \n");
printf("enter any operator: \n");
printf("enter 2nd num: \n");
printf("\n\n\n answer= %d", sum);
January 14th, 2013, 10:29 AM
says to read the very next character in the input buffer, which would be the newline from the Enter key when you entered the first number. If you rewrote the default case to output the ASCII code of ch (ie, printf with "%d") then you would see what ch's value is.
You want that scanf to ignore all white space that precedes the character you want it to read, so you need to tell it that thus (note the space before the %):
scanf(" %c \n\n",&ch);
January 14th, 2013, 11:06 AM
wow nice i gave space before %c and it working...
Originally Posted by dwise1_aol
thanksuuu very much..
can u explain why it happend?
January 14th, 2013, 01:25 PM
I already did explain why it happened.
Originally Posted by mo6361
Review scanf format strings. Any literal characters are what scanf is supposed to expect to see and to skip.
Review the concept of white space.
Review how scanf works.
Read the "commonly asked questions" thread, where this subject is undoubtedly covered. Your mistake shows up here with extreme regularity.
If you then still do not understand something, come back and ask that specific question.
Last edited by dwise1_aol; January 14th, 2013 at 02:34 PM.