RL> Could some one tell me how I can use C++ to input a line
RL> of ASCII-delimited text from a file and parse it into an
RL> array/structure/structured array(?)?
RL>
RL> A typical line might look like:
RL>
RL> "89765B","William","McIntire","70501",724,2,27.85
Pick your syntax, first.
What are your delimiters? space,commas
Heres a common example for space,comma,quoted delimited text.
while (s[index] = ' ') index++; // skip zero or more spaces
switch(s[index]) {
case ',' : { index++; break} // skip a comma
case '"' : { index2 = index;
while (s[index2] != '"') index2++;
//index to index2-1 is the range of a "" string
break;
}
default : { index2 = index;
while (isDigit(s[index2])) index2;
//index to index2-1 is the range of a number
break;
}
}
Basic algorithm
#1 - skip all spaces
#2 - test the first character,
it will tell you what kind of thing is coming next
#3 - repeat until end of text
--- GEcho 1.00
---------------
* Origin: Digital OnLine Magazine! - (409)838-8237 (1:3811/350)
|