Chapter 8

I l @ ve RuBoard

Chapter 8

  1. The statement putchar ( getchar ()); causes the program to read the next input character and to print it; the return value from getchar() is the argument to putchar() . No, getchar(putchar()) is invalid because getchar() doesn't use an argument and putchar() needs one.

    1. Display the H character.

    2. Sound the alert if the system uses ASCII.

    3. Move the cursor to the beginning of the next line.

    4. Backspace.

  2. count <essay >essayct or else count >essayct < essay

  3. Just c. is valid.

  4. It's a signal (a special value) returned by getchar() and scanf() to indicate that they have detected the end of a file.

    1. The output is as follows :

       If you qu 

      Note that the character I is distinct from the character i . Also note that the i is not printed because the loop quits upon detecting it.

    2. The output for ASCII is as follows:

       HJacrthjacrt 

      The first time through, ch has the value H . The ch++ causes the value to be used (printed) and then incremented (to I ). Then the ++ch causes the value to be incremented (to J ) and then used (printed). After that, the next character ( a ) is read, and the process is repeated. An important point to note here is that the incrementations affect the value of ch after it has been assigned a value; they don't somehow cause the program to move through the input queue.

  5. C's standard I/O library maps diverse file forms to uniform streams that can be handled equivalently.

  6. Numeric input skips over spaces and newlines, but character input does not. Suppose you have code like this:

     int score; char grade; printf("Enter the score.\n"); scanf("%s", %score); printf("Enter the letter grade.\n"); grade = getchar(); 

    If you enter 98 for the score, then press the Enter key to send the score to the program, you also sent a newline character, which becomes the next input character and is read into grade as the grade value. If you precede character input with numeric input, you should add code to dispose of the newline character before the character input takes place.

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