The following code compiles without a problem..
but while running it.. after the string is entered, the scanf ( for the char), doesn't wait for it to be entered and immediately proceeds to print the final statement (Tested with GCC and Turbo C++ 3.0). Why is this happening ?Code:#include <stdio.h>
main()
{
char s[20],c;
printf("Enter string : ");
scanf("%s",s);
printf("Enter char : ");
scanf("%c",&c);
printf("The string is %s and The char is %c",s,c);
}
After a little bit of tweaking...I found out that when the order of the two scanf statements is changed like...
it works correctly as expected.Code:#include <stdio.h>
main()
{
char s[20],c;
printf("Enter char : ");
scanf("%c",&c);
printf("Enter string : ");
scanf("%s",s);
printf("The string is %s and The char is %c",s,c);
}
My Problem is.. I do not want to change the order (the string should be scanned before the char). What should I do ?