Sams Teach Yourself C in 21 Days

(singke) #1
handling all input and output has definite advantages for the programmer. Of course, this
makes it essential that you understand what streams are and how they work. First, how-
ever, you need to know exactly what the terms inputandoutputmean.

What Exactly Is Program Input/Output? ......................................................

As you learned earlier in this book, a C program keeps data in random access memory
(RAM) while executing. This data is in the form of variables, structures, and arrays that
have been declared by the program. Where did this data come from, and what can the
program do with it?


  • Data can come from some location external to the program. Data moved from an
    external location into RAM, where the program can access it, is called input. The
    keyboard and disk files are the most common sources of program input.

  • Data can also be sent to a location external to the program; this is called output.
    The most common destinations for output are the screen, a printer, and disk files.
    Input sources and output destinations are collectively referred to as devices. The key-
    board is a device, the screen is a device, and so on. Some devices (the keyboard) are for
    input only, others (the screen) are for output only, and still others (disk files) are for both
    input and output. This is illustrated in Figure 14.1.
    Whatever the device, and whether it’s performing input or output, C carries out all input
    and output operations by means of streams.


338 Day 14

FIGURE14.1
Input and output can
take place between
your program and a
variety of external
devices.

Your
program

Screen

Modem

Serial port

Printer

Disk files

Keyboard

22 448201x-CH14 8/13/02 11:12 AM Page 338

Free download pdf