CC> Given situation: get a character and build a token until white s
CC> is reached. White space can be an actual space, tab, or newline
CC> character.
CC> No token can be over MAX_TOKEN_LEN in length.
CC> If you don't check for end of file you will run into an infinite
CC> // assume inf = ifstream
CC> char c;
CC> do {
CC> inf.get(c);
CC> if (inf.gcount() != 0) {
CC> if (current < MAX_TOKEN_LEN) {
CC> token[current++] = c;
CC> }
CC> }
CC> } while (((strrchr(" \t\n")==0) && (inf.gcount() != 0) &&
CC> (current < MAX_TOKEN_LEN));
CC> if ((inf.gcount() != 0)) {
CC> inf.putback(c);
CC> }
What about something like the following:
char token[MAX_TOKEN_LEN+1];
while (inf >> setw(sizeof token) >> token)
if (isspace(inf.peek())
// process token here
else
// token too long
Feel free to use this design, but you should test it first!
CC> Notice that there will be _only_ one end of file reached per file
CC> If I check every character read from the file 3 times I have a sl
CC> slow, slow piece for code.
Have you tested the speed of exception handling? I haven't, neither,
but it's said to be slow, slow, slow.
Thomas
---
þ MM 1.0 #0113 þ Have *I* been forgetful? Sorry, I don't remember.
---------------
* Origin: McMeier & Son BBS (2:301/138)
|