-
Parse line using strtol
Hi I am trying to parse a line of text from a file using strtol, but I can only seem to get the first word on the line. From the M$ help file it says the second paramater is a pointer to wherever the last function stops, and the third is the number base. So why wont this work:
Code:
char* endptr;
in.getline(str, FILTER_NAME_MAX_LINE-2);
w = (Uint16)strtol(str, &endptr, 10);
h = (Uint16)strtol(str, &endptr, 10);
When my text file line looks like:
:confused:
-
Code:
w = (Uint16)strtol(str, &endptr, 10);
if (endptr)
h = (Uint16)strtol(endptr, &endptr, 10);
should work.
--
Mats
-
You start back at the beginning for the second call. The first parameter tells strtol where to start, and it doesn't save any state like strtok, so you have to remember where to continue (endptr tells you this).
-
Thanks guys. I dident realize i had to pass the last position into the later calls, but it seems obvious now.