#include
int main()
{
char ch;
int i;
printf ("Enter any number: ");
scanf ("%d",&i);
printf ("Enter any character:... ");
scanf ("%c",&ch);
printf ("\n%d %c",i,ch);
return 0;
}
Guys, tell me why in the output it is not reading the character properly, or tell me how to make possibleto read the second scanf statement. Leave explanation also why it is behaving so...?
4 comments:
Actually when ur reading character scanf will take "space" and "Enter" as a character.
so
if u give input as
For eg:
4[ENTER]
a
OR
4[SPACE]a
In both cases ENTER and SPACE are considerd as input characters and red by scanf.
If you give input like this,
4a
It will take 4 for Integer,and 'a' for character.
....thats a good one, its true. That space or enter will cease to problem, but plz follow up with the solution too..!
Plz provide what will be the solution.?
Hi guys.. Actually the above comment by Gurudat is right.. But the solution is we have to use "fflush(stdin)" before reading the character. It will flush out the buffer and make the buffer free to read the character we given..
Post a Comment