From: Jeremy B. <je...@de...> - 2006-07-20 22:48:54
|
>From MSDN: %c: When used with scanf functions, specifies single-byte character; when used with wscanf functions, specifies wide character. White-space characters that are ordinarily skipped are read when c is specified. To read next non-white-space single-byte character, use %1s; to read next non-white-space wide character, use %1ws. So the program is correctly reading your text. It reads 'u' '\r' '\n' '6', and if you would have used %d in your printf statements you would have seen this. ----- Original Message ----- From: "Felix VIII" <alp...@ho...> To: <min...@li...> Sent: Thursday, July 20, 2006 5:32 PM Subject: [Mingw-users] scanf, fscanf, gets, fgetc,and mostly-every-other-input-function problem > Alas, I thought the problem was resolved, but no, it reoccurs: > > [test.c file]: > #include <stdio.h> > > int main() > { > char a,b,c,d; > int e,f,g,h; > printf("start"); > e=fscanf(stdin,"%c",&a); > f=fscanf(stdin,"%c",&b); > g=fscanf(stdin,"%c",&c); > h=fscanf(stdin,"%c",&d); > printf("\n\n\"%c%c%c%c\"=character input\n",a,b,c,d); > printf("%d%d%d%d=fscanf output",e,f,g,h); > } > > [entered into command prompt]: > C:\MinGW>gcc test.c -o test.exe > > C:\MinGW>test.exe > startu > 6 > > "u > 6"=character input > 1111=fscanf output > C:\MinGW>test.exe > start > > > " "=character input > 1111=fscanf output > [the actual characters entered for the first test are > 'u','<return>','<space>', and '6'. For the second case the characters are > all spaces.] > [ I have tested this with scanf, gets, fgetc with similar arrangements and > the results have been the same] > [end] > > And that is my problem; I have been told that scanf() stops reading input > when it encounters a space, but that appears not to be so here. As I said > earlier, the scanf and gets functions only work every other time, I > believe > that is because when I hit the <return> key the <return> is automatically > entered as the input to the next input function. > > ??? > > _________________________________________________________________ > Express yourself instantly with MSN Messenger! Download today - it's FREE! > http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys -- and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > MinGW-users mailing list > Min...@li... > > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users > |