[ Post New Message | Post Reply to this One | Send Private Email to Steve Heller | Help ]

Reading ASCII characters

from Steve Heller (stheller@koyote.com)

The original definition of the line feed was that it caused the teletypewriter to advance to the next line, whereas the carriage return character returned the carriage to the beginning of the line. As I said, these are historical artifacts from the dawn of computing. The application here is that the newline, consisting of either a line feed character or a line feed character followed by a carriage return (depending on the operating system) is used in text editors to indicate the end of line. Thus, if you write a file with the data elements separated by a newline, it will be readable in most text editors. This simplifies figuring out what your program is doing.

There is a list of these "control characters" in the back of most programming reference manuals. Most of them aren't used very much any more, because we don't use teletypewriters for output; controlling the output of such devices was their main function.

All you should need is the newline and space characters to write your program. Not that you shouldn't know about the other control characters, but they aren't relevant to your question.

To read arbitrary characters from a file, I would use "get", which takes one argument of char type and reads the next character from the input stream. For example, if you're reading from a stream called instream, it would go like this:

while (instream.get(c))
  {
  // process
  }

When there aren't any more characters left in the input stream, the condition will be false, so the loop will end.

(posted 9091 days ago)

[ Previous | Next ]