[NTLUG:Discuss] fflush dosn't work

Geremy L. Hamlett ghamlett at swbell.net
Sun Jul 14 22:34:01 CDT 2002


I am having a problem with some .c code. Specificlly w/ the fflush syntax.

Here is some sample code:

#include <stdio.h>

int main(void){

	char ch = 'N';

	while (ch != 'y'){
		printf("Enter a letter:");
		fflush(stdin);
		scanf("%c", &ch);
	}

return (0);
}


Basicly what happens is it enters the loop, and prompts to enter a letter.
Then after the input the loop checks the true/false condition of the loop.

When you type a letter and then enter, it then checks.  The fflush command 
is suposed to flush the input and remove the \r token, But it dosn't.

after compiling w/ gcc and run it. The fflush dosn't seam to remove any 
thing.

What Do I need to do to utilize fflush?

Thanks for your help,
-- 
Geremy L. Hamlett

http://omega.uta.edu/~glh6688
"All Your Base are Belong to Us"





More information about the Discuss mailing list