Each entry is delimited by a comma.
Here's the actual entry in the file: guardian,guardian.png,0,0,85,75,... etc.
Here's my code to extract it:
int lastPlace = 0;
int delimiter = 0;
delimiter = line.find(",", lastPlace);
// entry is the label/string entry to update
entry = line.substr(lastPlace, delimiter);
lastPlace = delimiter + 1;
delimiter = line.find(",", lastPlace);
// now the fileName
// --- !!! Here is where it screws up !!! ---
imageFileName = line.substr(lastPlace, delimiter);
lastPlace = delimiter + 1;
delimiter = line.find(",", lastPlace);
// the starting X and Y positions
startX = atoi(line.substr(lastPlace, delimiter).c_str());
lastPlace = delimiter + 1;
... etc ..
As you can see, it finds the next comma, and returns a substring from the last place it was. In this case, I set the int variable 'lastPlace' to 0 initially, and then to the beginning of the next entry each time there-after.
What happens is, 'guardian' is read in for the string 'entry'.
'guardian.png,0,0,85,7' is read in for the string 'imageFileName'
'0' is read in for the int startX,
'0' is read in for the int startY,
'85' is read in for imageWidth
'75' is read in for imageHeight
So the problem is that it's reading everything else correctly, but not the correct filename. What's even more strange, is that the comma delimiter for the second entry (imageFileName) is at position 21, and there are 21 characters in the 'imageFileName' variable that is input. See how's it's truncated? The numbers at the end of it are the following variables for startX, startY, imageWidth, and the beginning of imageHeight. Why is it doing that?
So it's almost as if the second read is finding the correct comma position for the delimiter, it's finding the right position for the lastPlace it was, but for some reason the substr method is returning the next 21 characters in sequence, rather than returning the string inbetween index 'lastPlace' and index 'delimiter' (which is 21).
Does this make any sense at all?
-Gardon












