From: "David P. Hack" Newsgroups: comp.os.msdos.djgpp Subject: Buffered input Lines: 36 Message-ID: <6_Ap1.22$s7.1149262@alpha.sky.net> Date: Sat, 11 Jul 1998 03:29:06 GMT NNTP-Posting-Host: 209.90.5.3 NNTP-Posting-Date: Fri, 10 Jul 1998 22:29:06 CDT Organization: SkyNET Corporation To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk I am a green C programmer and have a question about djgpp's handling of input and the scanf() function. The following program goes into a loop if a correct input is not received. What I expected it to do was to reprompt if a correct input is not received. When I compile this source and run it under Turbo C, it reprompts but under djgpp it loops. I assume this has something to do with djgpp's use of buffered input and I have read some of the bug descriptions that seem to be related to this but I am confused. Can anyone help me understand why this loops and why it runs differently from Turbo C? Thanks Dave Hack /* shel06.c */ /* Validate a single character input with scanf */ #include #include main() { char c; /* input character */ int intScanres; /* scanf function return value */ clrscr(); do { fflush(stdin); printf("Please input (Y)es or (N)o: "); intScanres = scanf("%[YyNn]", &c); printf("intScanres is %d\n",intScanres); } while(intScanres != 1); printf("The character entered is: %c",c); return 0; /* end of main() function */ }