...stuck on a book problem

Mar 2, 2013 at 8:44pm
This one is from Prof. Horstmann.
I just can't put together the idea he has set up as a programming book excercise. I hope that there is somebody out there who is doing something that works a little better than what I am doing.

"
Write a program that reads each line in a file, reverses its characters, and writes the resulting line to the same file. Use the following pseudocode:

While the end of the file has not been reached
pos1 = current get position
Read a line
If the line was successfully read
pos2 = current get position
Set put position to pos1
Write the reveresed line
Set get position to pos2
"


So I am trying to do everything he has outlined. However, two things seem contradictory, these two lines : "While the end of the file has not been reached", and "If the line was successfully read" .

If you try to program the outlining above, it doesn't do anything at all, I think that I am missing something. I am not using anything to check if the line was actually being read other than cycling the getline function in a while loop. It is just not working at all, and I don't see how re-checking if the line was read helps. I know that I am missing something here.

...from page 380-1 as P8.8 from "C++ for Everyone" 2nd Edi. Cay Horstmann and as Wiley the Publisher.
Last edited on Mar 2, 2013 at 8:46pm
Mar 2, 2013 at 8:57pm
The way he writes it, it sounds like he wants you to follow the steps below continuously and check at appropriate points if you should terminate.

He hasn't written a program, he's written an algorithm pseudo-code; it's up to you to figure out where to put the checks, or in a structured programming language, what loop to use and how to write it within the loop.
Last edited on Mar 2, 2013 at 10:37pm
Mar 2, 2013 at 9:07pm
Yeah, it would seem as if he dumped out all the parts, leaving but just small tattered note with which to deal. I can't make anything out of the parts, and I have been trying for weeks now. I think I lost a piece or two somewhere.
Topic archived. No new replies allowed.