C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-01-2009, 06:17 AM   #1
Registered User
 
Join Date: Feb 2009
Posts: 9
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.
mashour06 is offline   Reply With Quote
Old 06-01-2009, 06:22 AM   #2
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 04:03 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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