Chapter Summary

I l @ ve RuBoard

Chapter Summary

Many programs use getchar () to read input character by character. Typically, systems use line-buffered input, meaning that input is transmitted to the program when you press Enter. Pressing Enter also transmits a newline character that may require programming attention. ANSI C requires buffered input as the standard.

C features a family of functions, called the standard I/O package, that treats different file forms on different systems in a uniform manner. The getchar() and scanf() functions belong to this family. Both functions return the value EOF (defined in the stdio.h header) when they detect the end of a file. UNIX systems enable you to simulate the end-of-file condition from the keyboard by typing Ctrl+D at the beginning of a line; DOS systems use Ctrl+Z for the same purpose.

Many operating systems, including UNIX and DOS, feature redirection, which enables you to use files instead of the keyboard and screen for input and output. Programs that read input up to EOF can then be used either with keyboard input and simulated end-of-file signals or with redirected files.

Interspersing calls to getchar() with calls to scanf() can cause problems when scanf() leaves a newline character in the input just before a call to getchar() . By being aware of this problem, however, you can program around it.

When you are writing a program, plan the user interface thoughtfully. Try to anticipate the sort of errors users are likely to make and then design your program to handle them.

I l @ ve RuBoard


C++ Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 314
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net