The code that I am trying to write, is supposed to search a string for a left bracket ('{'), then begin to copy information afterwards to be parsed later by the program. And any information between the time the program is not copying characters, to the time it finds the character needed to allow copy of characters will result in a termination of the program. I first find a word in a text file (which is "Dimensions") using find(). I add 10 to that word so it starts just right after the 's' in dimensions. I use an integer (celement) to store the character location right after 's', and to check each element after that character in the string map.level to see if the character '{' comes up. While it is searching for the left bracket, it is supposed to make sure no other characters, besides '\n' and ' ', are present between the left bracket '{' and the 's' in Dimentions.
Now the problem. The problem is that it does not seem to differentiate spaces (' ') in the string which it has(the full string shown before the block of code), as not an error, and instead, it sees it as an error and exits. I have made another program which does the exact thing, and works, but this one seems to have a problem which I have been overlooking.
Here is part of the string I'm pulling information from and using in my program. The beginning is the only necessary element of the string:
Code:
Dimensions { -nebula x0 y0 w800 h600 m1 -gravel_whole x0...
Here is the code that is having problems:
Code:
if ( map.level.find("Dimensions") != string::npos )
{
celement = map.level.find("Dimensions") + 10;
}
else
{
cout << "\nCould not find \"Dimensions\" in map.level or levels.txt, in MapParse. Exit failure!\n";
_EXIT_( 1 );
}
for ( ; map.level[celement] != '{'; ++celement )
{
if ( map.level[celement] == '}' )
{
cout << "\n\t'}' was found while attempting to locate '{'. Levels was setup incorrectly. MapParse, exit failure!\n";
_EXIT_( 1 );
}
if ( map.level[celement] != ' ' || '\n' )
{
cout << "\n\tUnknown characters found after \"Dimensions\" and before '{' in MapParse.\n"
<< "\n\tThe character found was, " << map.level[celement] << ".\n\tLocation: map.level[" << celement << "].\n"
<< "\n\tThe whole string is, \n\n"
<< map.level << "\nExit failure!\n";
_EXIT_( 1 );
}
}
I will give more info if needed.