Sams Teach Yourself C in 21 Days

(singke) #1
Answers 865

F



  1. Buffered input is sent to the program only when the user presses Enter. Unbuffered
    input is sent one character at a time, as soon as each key is pressed.

  2. Echoed input automatically sends each character to stdoutas it is received; une-
    choed input does not.

  3. You can “unget” only one character between reads. The EOFcharacter can’t be put
    back into the input stream with unget().

  4. With the newline character, which corresponds to the user’s pressing Enter.

  5. a. Valid
    b. Valid
    c. Valid
    d. Not valid. There is not an identifier of q.
    e. Valid
    f. Valid
    10.stderrcan’t be redirected; it always prints to the screen. stdoutcan be redirected
    to somewhere other than the screen.


Exercises

1.printf( “Hello World” );
2.fprintf( stdout, “Hello World” );
puts( “Hello World”);
3.fprintf( stdaux, “Hello Auxiliary Port” );


  1. The code is as follows:
    char buffer[31];
    scanf( “%30[^*]”, buffer );

  2. The code is as follows:
    printf( “Jack asked, \”What is a backslash\?\”\nJill said, \
    \”It is \’\\’\””);

  3. Hint: Use an array of 26 integers. To count each character, increment the appropri-
    ate array element for each character read.

  4. Hint: Get a string at a time, and then print a formatted line number followed by a
    tab and the string. Second Hint: Check out the Print_It program in Type & Run 1!


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

Free download pdf