T
Till Crueger
Hi,
I have a little problem with the following code:
#include <stdio.h>
int main(void) {
char input='\0';
while(input!='q') {
printf("Menu\n");
fflush(stdout);
scanf("%c",&input);
/* do something */
}
}
After I get an input there is still a trailing newline. However I always
thought the next scanf would consume this newline. I checked with the FAQ,
but all I found was section 12.18 which covers this issue a bit. The
solution it gives is to only use scanf(), which in this case I do. Any
other hints on what to do about this?
Thanks,
Till
I have a little problem with the following code:
#include <stdio.h>
int main(void) {
char input='\0';
while(input!='q') {
printf("Menu\n");
fflush(stdout);
scanf("%c",&input);
/* do something */
}
}
After I get an input there is still a trailing newline. However I always
thought the next scanf would consume this newline. I checked with the FAQ,
but all I found was section 12.18 which covers this issue a bit. The
solution it gives is to only use scanf(), which in this case I do. Any
other hints on what to do about this?
Thanks,
Till