pete
9/1/2011 11:15:00 PM
Bill Cunningham wrote:
>
> Where is the right place to put fflush in a file IO operation?
If you want a message to appear on standard output,
which asks the user for input,
then use fflush(stdout) after the message code,
before the input code.
/* BEGIN new.c */
#include <stdio.h>
int
main(void)
{
int integer;
printf("Enter an integer: ");
fflush(stdout);
if (scanf("%d", &integer) == 1) {
printf("\nThe integer is %d\n", integer);
} else {
puts("\nTry harder next time!");
}
return 0;
}
/* END new.c */
--
pete