Sams Teach Yourself C in 21 Days

(singke) #1

  1. You might think that the defaultneeds to go at the bottom of the switchstate-
    ment, but this isn’t true. The defaultcan go anywhere. There is a problem, how-
    ever. There should be a breakstatement at the end of the defaultcase.

  2. The code is as follows:
    if( choice == 1 )
    printf(“You answered 1”);
    else if( choice == 2 )
    printf( “You answered 2”);
    else
    printf( “You did not choose 1 or 2”);

  3. The code is as follows:
    do {
    / any C statements /
    } while ( 1 );


Answers for Day 14

Quiz


  1. A stream is a sequence of bytes. A C program uses streams for all input and out-
    put.

  2. a. A printer is an output device.
    b. A keyboard is an input device.
    c. A modem is both an input and an output device.
    d. A monitor is an output device. (Although a touch screen would be an input
    device and an output device.)
    e. A disk drive can be both an input and an output device.

  3. All C compilers support three predefined streams:stdin(the keyboard),stdout
    (the screen), and stderr(the screen). Some compilers, also support stdprn(the
    printer), and stdaux(the serial port COM1). Note that the Macintosh doesn’t sup-
    port the stdprnfunction.

  4. a.stdout
    b.stdout
    c.stdin
    d.stdin
    e.fprintf()can use any output stream. Of the five standard streams, it can use
    stdout,stderr,stdprn, andstdaux.


864 Appendix F

49 448201x-APP F 8/13/02 11:22 AM Page 864

Free download pdf