-
programming exercise
Hello everybody,
as a beginner in C language I have a problem solving the next exercise (the exercise is from Stephen Prata's C primer plus book), could anyone help me solving it?
the exercise says:
Write a program that reads input as a stream of characters until encountering EOF. Have the program print each input character and its ASCII decimal value. Note that characters preceding the space character in the ASCII sequence are nonprinting characters. Treat them specially. If the nonprinting character is a newline or tab, print \n or \t, respectively. Otherwise, use control-character notation. For instance, ASCII 1 is Ctrl+A, which can be displayed as ^A. Note that the ASCII value for A is the value for Ctrl+A plus 64. A similar relation holds for the other nonprinting characters. Print 10 pairs per line, except start a fresh line each time a newline character is encountered.
Thank you very much.
-
Sure, we can help.
However, we are not going to DO the exercise for you, so you'd better come up with either:
1. Some code that you think would do (part of) the exercise. It helps if you can also explain what isn't working (e.g. compiler errors or crashes) and/or how it is working vs. what you expect.
2. Ask some specific question as to a particular part of the problem.
With ALL problems, you may want to split it into portions, write something that does that bit, and then extend it to do more and more "usefulness" until it's complete.
So a first step may be to write a program that reads input until EOF. Then start printing things, then "make it pretty" by handling tab and newline, then handle other control characters.
--
Mats