Need Help/Advice With This C Program... 
Author Message
 Need Help/Advice With This C Program...

I have an assignment that I could use some help getting started on...

Write a C program that will examine the data presented to standard input
and print the lines (to standard output) in reverse order.
Lines that begin with white space (blanks, tabs, and newlines) should
not be
printed at all. Also, print only the last 20 characters of each line.
The
last of those 20 characters will be a newline, of course. For example,
applying your p2 to this paragraph (and the lines at the top of this
file)
yields:

yields:
e top of this file)
urse. For example,
of each line. The
ines) should not be
) in reverse order.

This program is intended to familiarize you with for loops and character

arrays; thus, you are required to avoid using string variables and
string
functions such as strlen() and strcpy() in this assignment; I want to
force you to move data one character at a time, preferably with
pointers.
(This is not meant to dissuade you from using the normal C string
paradigm;
you should still be able to use %s in your printf() statements when you
print the results.)

Data MUST be stored internally as arrays, and MUST *NOT* be written to
an
intermediate file. It is (conceptually) simple to declare the internal
data structure to be a two-dimensional array, but this will be
inconvenient if
we use this code in our next program, so you MUST NOT use a
two-dimensional array.
Instead, put all the data you wish to print out in a one-dimensional
array,
and keep track of the beginnings of your strings with an additional
array
of pointers. This requirement is intended to help you visualize how data

is stored and accessed.

You need not handle lines of "unreasonably long" lengths, but you MUST
decide on a limitation, document and justify your decision. (Remember,
you
are only printing out the last 20 characters, but 20 is definitely NOT a

reasonable limit). There is a large range of possible choices that I
would consider OK, depending on the justification that you give.
You should make a design decision, document, and implement your approach
to
error recovery. What your program will do with input that is "too big"
is
purposely not specified in this assignment; part of your grade will be
based
on your design. Big hint: make your program as robust as possible --
process
as much of the file as you can.

If the maximums are exceeded, (at least) an appropriate error message
should be
sent to stderr. We have not yet covered writing to files, but all you
really
need to do is replace the statement

printf(whatever);
with
fprintf(stderr, whatever);

in the final version.

Your main program MUST return a value when it finishes. It is up to you
to design a rational scheme of return values, consistent with the
paradigm
used in UNIX. Document your scheme, and explain why your choice is
useful.
(You should be able to return something more significant than what was
implemented in Program 1.)

Remember that the previous program was the only one that could be coded
as
one monolithic main() function. This, and all future programs, MUST use
a
modular design. In this particular assignment, put all the code you
write
in the directory discussed in class; do not create your own .h files or
other .c files.

Any help would be greatly appreciated, I am just a little stuck on where
all to begin. I have decided that it would be good to limit lines to 80
characters long. When a line exceeds that length, I want to print out a
warning to stderr and then continue on with the other lines, SKIPPING
the line that exceeded the line length limit.

Thanks in advance!
-mogrefy



Thu, 16 Oct 2003 06:37:53 GMT  
 Need Help/Advice With This C Program...
The instructor has told you the steps to take -- see comments inline.


Quote:
> I have an assignment that I could use some help getting started on...

> Write a C program that will examine the data presented to standard input
> and print the lines (to standard output) in reverse order.
> Lines that begin with white space (blanks, tabs, and newlines) should
> not be
> printed at all. Also, print only the last 20 characters of each line.
> The
> last of those 20 characters will be a newline, of course. For example,
> applying your p2 to this paragraph (and the lines at the top of this
> file)
> yields:

> yields:
> e top of this file)
> urse. For example,
> of each line. The
> ines) should not be
> ) in reverse order.

> This program is intended to familiarize you with for loops and character

> arrays; thus, you are required to avoid using string variables and
> string
> functions such as strlen() and strcpy() in this assignment; I want to
> force you to move data one character at a time, preferably with
> pointers.
> (This is not meant to dissuade you from using the normal C string
> paradigm;
> you should still be able to use %s in your printf() statements when you
> print the results.)

> Data MUST be stored internally as arrays, and MUST *NOT* be written to
> an
> intermediate file. It is (conceptually) simple to declare the internal
> data structure to be a two-dimensional array, but this will be
> inconvenient if
> we use this code in our next program, so you MUST NOT use a
> two-dimensional array.

STEP #1 follows:

Quote:
> Instead, put all the data you wish to print out in a one-dimensional
> array,

STEP #2 follows:

Quote:
> and keep track of the beginnings of your strings with an additional
> array
> of pointers. This requirement is intended to help you visualize how data

> is stored and accessed.

STEP #3 follows:

Quote:
> You need not handle lines of "unreasonably long" lengths, but you MUST
> decide on a limitation, document and justify your decision. (Remember,
> you
> are only printing out the last 20 characters, but 20 is definitely NOT a

> reasonable limit). There is a large range of possible choices that I
> would consider OK, depending on the justification that you give.

STEP #4 follows:

Quote:
> You should make a design decision, document, and implement your approach
> to
> error recovery. What your program will do with input that is "too big"
> is
> purposely not specified in this assignment; part of your grade will be
> based
> on your design. Big hint: make your program as robust as possible --

STEP #5 follows:

Quote:
> process
> as much of the file as you can.

STEP #6 follows:

Quote:
> If the maximums are exceeded, (at least) an appropriate error message
> should be
> sent to stderr. We have not yet covered writing to files, but all you
> really
> need to do is replace the statement

> printf(whatever);
> with
> fprintf(stderr, whatever);

> in the final version.

STEP #7 follows:

Quote:
> Your main program MUST return a value when it finishes. It is up to you
> to design a rational scheme of return values, consistent with the
> paradigm
> used in UNIX. Document your scheme, and explain why your choice is
> useful.
> (You should be able to return something more significant than what was
> implemented in Program 1.)

STEP #8 follows:

- Show quoted text -

Quote:
> Remember that the previous program was the only one that could be coded
> as
> one monolithic main() function. This, and all future programs, MUST use
> a
> modular design. In this particular assignment, put all the code you
> write
> in the directory discussed in class; do not create your own .h files or
> other .c files.

> Any help would be greatly appreciated, I am just a little stuck on where
> all to begin. I have decided that it would be good to limit lines to 80
> characters long. When a line exceeds that length, I want to print out a
> warning to stderr and then continue on with the other lines, SKIPPING
> the line that exceeded the line length limit.

> Thanks in advance!
> -mogrefy

1. you have an array of characters
2. you have an array of pointers into the array of characters
3. your choice of length is ok, but you may not want to discard the whole
line (see step #5).
4. handle errors from your library calls
etc.

if you code up each of the steps in turn, you should start to see the
program take on a life of its own.

--
bcingu

 -----
Brainbench MVP for High IT Aptitude
http://www.brainbench.com



Thu, 16 Oct 2003 09:52:16 GMT  
 Need Help/Advice With This C Program...

<homework assignment snipped>

"Need Help/Advice With This C Program..."

What C-program? Next time, please use a font bigger that 0. (or was it white
on white?)

--
-hs-    "spaces, not tabs" email: emdel at noos.fr
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://secure.dinkumware.com/htm_cl/
FAQ de FCLC : http://www.isty-info.uvsq.fr/~rumeau/fclc



Thu, 16 Oct 2003 15:49:14 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help!!! Novice CS Advice

2. Reuse of cs files, namespace, arch advice pls

3. newbe/cs student, need help w/ code

4. programming language advice needed

5. Need advice on C program

6. need programming advice

7. New to programming...advice needed!

8. Programming advice needed

9. Program freezes with Sleep() - now i need some advice about a multi-threaded app

10. Internet programming advice needed

11. Advice needed: Alternative make programs

12. Needing advice on Wav programming

 

 
Powered by phpBB® Forum Software