Sams Teach Yourself C in 21 Days

(singke) #1
Working with the Screen, Printer, and Keyboard 375

14


Exercises ........................................................................................................


  1. Write a statement to print “Hello World”to the screen.

  2. Use two different C functions to do the same thing the function in exercise 1 did.

  3. Write a statement to print “Hello Auxiliary Port”to the standard auxiliary port.

  4. Write a statement that gets a string 30 characters or shorter. If an asterisk is
    encountered, truncate the string.

  5. Write a single statement that prints the following:
    Jack asked, “What is a backslash?”
    Jill said, “It is ‘\’”
    Because of the multitude of possibilities, answers are not provided for the follow-
    ing exercises; however, you should attempt to do them.
    6.ON YOUR OWN:Write a program that redirects a file to the printer one character
    at a time.
    7.ON YOUR OWN:Write a program that uses redirection to accept input from a
    disk file, counts the number of times each letter occurs in the file, and then dis-
    plays the results on-screen. (A hint is provided in Appendix F, “Answers.”)
    8.ON YOUR OWN:Write a program that prints your C source files. Use redirection
    to enter the source file, and use fprintf()to do the printing.
    9.ON YOUR OWN:Modify the program from exercise 8 to put line numbers at the
    beginning of the listing when it is printed. (A hint is provided in Appendix F,
    “Answers.”)
    10.ON YOUR OWN:Write a “typing” program that accepts keyboard input, echoes
    it to the screen, and then reproduces this input on the printer. The program should
    count lines and advance the paper in the printer to a new page when necessary. Use
    a function key to terminate the program.


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

Free download pdf