Does anyone have a good fail-safe method to parse out a text string that is column delimited (i.e. columns 1-4, which may have whitespace, is reserved for a particular variable). I have the following set up to read lines of input data that need to be parsed apart:
The input data has the following format:
FORTRAN
Columns DataType Format Description
1-4 Integer I4 Plot Identification (i.e., plot numbers)
5-7 Integer I7 Tree identification
8-13 Real F6.0 Tree count
14 Integer I1 Tree history code
15-17 Character A3 Species code
.......more I won't list in this request.
An example file that I have looks like (more columns than I have shown above):
1262 1.061WF 135 13 74 0 0562 198 0 0 02113 92 031
1264 41WF 41 8 28 0 0462 198 0 0 02113 92 031
1266 41WF 34 0 0 0 0362 198 0 0 02113 92 031
1270 201OT 16 0 7 0 14762 198 0 0 02113 92 031
1 0 2201OT 1 0 0 0 00 0 0 0 0 0 02113 92 031
1267 41LP 33 13 17 0 0330 362 195 02113 92 031
1271 201OT 14 0 9 0 26641 162 198 02113 92 031
1 0 601OT 1 0 0 0 00 0 0 0 0 0 02113 92 031
1272 1.061WF 139 19 79 0 0315 1 0 0 0 02113 92 031
1273 1.061WF 170 0 0 0 0315 1 0 0 0 02113 92 031
The WHITESPACES are important and they count towards the width of the column, so that every line has exactly the same # of columns (59).
I am greatly appreciative of any recommendations or tips.
David H. Graetz
Code:
while((GetStatus = fgets(TempString,MAX_CHAR_PER_TREE_RECORD+1,READ)) != NULL)
{
//Now parse through TempString to extract data out of particular columns
***WHAT IS MY BEST OPTION HERE
***I tried some sscanf calls but had difficulties
}//end while()
The input data has the following format:
FORTRAN
Columns DataType Format Description
1-4 Integer I4 Plot Identification (i.e., plot numbers)
5-7 Integer I7 Tree identification
8-13 Real F6.0 Tree count
14 Integer I1 Tree history code
15-17 Character A3 Species code
.......more I won't list in this request.
An example file that I have looks like (more columns than I have shown above):
1262 1.061WF 135 13 74 0 0562 198 0 0 02113 92 031
1264 41WF 41 8 28 0 0462 198 0 0 02113 92 031
1266 41WF 34 0 0 0 0362 198 0 0 02113 92 031
1270 201OT 16 0 7 0 14762 198 0 0 02113 92 031
1 0 2201OT 1 0 0 0 00 0 0 0 0 0 02113 92 031
1267 41LP 33 13 17 0 0330 362 195 02113 92 031
1271 201OT 14 0 9 0 26641 162 198 02113 92 031
1 0 601OT 1 0 0 0 00 0 0 0 0 0 02113 92 031
1272 1.061WF 139 19 79 0 0315 1 0 0 0 02113 92 031
1273 1.061WF 170 0 0 0 0315 1 0 0 0 02113 92 031
The WHITESPACES are important and they count towards the width of the column, so that every line has exactly the same # of columns (59).
I am greatly appreciative of any recommendations or tips.
David H. Graetz