[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Help me stay away from visual C++ :)



On Mon, 26 Jul 1999, Moses Leslie wrote:

> int test;
> for(;;)
> {
>         printf("Status is %d\n",scanf("%d",&test));
>         fflush(stdin); 
> }

> prints out "Status is 1" if it gets an int, but freaks out and keeps printing
> "Status is 0" over and over if you give it a char.  The same snippet works fine
> under visual C++.  Is this something that's (most likely) broken in vc++, or
> perhaps (less likely) broken in glibc 2.1?  All I have to test it on is a
> potato box, so I don't know if other versions of gcc have the same problem.

fflush doesn't do anything (or at least isn't supposed to) for input
streams, fflush is ment to flush pending output, not discard pending
input. So what is happening is that glibc ignores the fflush and
continually rescans that invalid character in a loop.

Jason


Reply to: