programming exercise

This is a discussion on programming exercise within the C Programming forums, part of the General Programming Boards category; Hello everybody, as a beginner in C language I have a problem solving the next exercise (the exercise is from ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    10

    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.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Line of data input method
    By larry_2k4 in forum C Programming
    Replies: 2
    Last Post: 04-28-2009, 11:34 PM
  2. Can I get some idea for exercise?
    By Rokemet in forum C++ Programming
    Replies: 6
    Last Post: 11-22-2007, 08:10 AM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 08:40 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. any recommended exercise book for C++?
    By gogo in forum C++ Programming
    Replies: 5
    Last Post: 11-07-2001, 03:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21