Clearing the input stream
Someone told me to use this to clear input buffer
Code:
while((ch=getchar())!='\n' && ch!=EOF);
...and now this is giving me a warning:
Code:
#include<stdio.h>
int main()
{
char a,b,ch;
printf("\nEnter a character:");
a=getchar();
while((ch=getchar())!='\n' && ch!=EOF);
printf("\nEnter another one:");
b=getchar();
while((ch=getchar())!='\n' && ch!=EOF);
printf("You entered %c and %c\n",a,b);
return 0;
}
13:3: warning: no newline at end of file :confused:
The program works as expected, though.