Stdio

12. Stdio

12.1What's wrong withthe code"char c; while((c = getchar()) != EOF) ..."?

12.2Whywon'tthecode `` while(!feof(infp)) { fgets(buf, MAXLINE, infp); fputs(buf, outfp); } '' work?

12.4My program's prompts and intermediate output don't always show upon the screen.

12.5How can I read one character at a time,without waiting for the RETURN key?

12.6How can I print a '%' character with printf?

12.9How canprintf use %f for type double, if scanf requires %lf?

12.10How can I implement a variable field width with printf?

12.11How can I print numbers with commas separating the thousands?

12.12Why doesn't the callscanf("%d", i) work?

12.13Why doesn'tthe code"double d; scanf("%f", &d);" work?

12.15How can I specify a variable width in a scanf format string?

12.17When I readnumbersfrom the keyboard with scanf "%d\n", it seems to hang until I type one extra line of input.

12.18I'm reading a number with scanf %d and then a string with gets(), but the compiler seems to be skipping the call to gets()!

12.19I'm re-prompting the user if scanf fails, but sometimes it seems to go into an infinite loop.

12.20Why does everyone say not to use scanf? What should I use instead?

12.21How can I tell how much destination buffer space I'll needfor an arbitrary sprintf call? How can I avoid overflowing the destination buffer with sprintf?

12.23Why does everyone say not to use gets()?

12.24Why does errno contain ENOTTY after a call to printf?

12.25What's the difference between fgetpos/fsetpos and ftell/fseek?

12.26Will fflush(stdin) flush unread characters from the standard input stream?

12.30I'm trying to update a file in place,by using fopen mode "r+", but it's not working.

12.33How can I redirect stdin or stdout from within a program?

12.34Once I've used freopen, how can I get the original stream back?

12.38How can I read a binary data file properly?


top