Thanks for the replies..
I guessed that it should be due to the buffering..(now I know it for sure!)
Code:
/* If you are sure that unwanted data is in the input stream,
you can use some of the following code snippets to remove
them. However, if you call these when there is no data in the
input stream, the program will wait until there is, which gives
you undesirable results. */
while ((ch = getchar()) != '\n' && ch != EOF);
I also found out that calling getchar() immediately after the scanf("%c",&c); solves the problem...
my code now looks like
Code:
#include <stdio.h>
main()
{
char s[20],c;
printf("Enter string : ");
scanf("%s",s);
printf("Enter char : ");
scanf("%c",&c);
c = getchar();
printf("The string is %s and The char is %c",s,c);
}
linuxdude: I saw the title and laughed.