Why make it hard on yourself? Just use array subscripts for this task...like:
Code:
int next_positition( char string, int *curr ) {
int pos, temp;
bool found = false;
for( pos = *curr; string[pos] != NULL; pos++)
{
if(string[pos] = '"' )
{
found = true;
break;
}
}
if( !found )
return -1;
found = false;
for(temp = *curr; string[temp] != NULL; temp++)
{
if(string[temp] = '"' )
{
found = true;
}
}
if( !found )
*curr = 0;
else
*curr = pos + 1;
return pos;
}
//..............................................................................//
int main() {
char string[] = " \"I think, therefore - I am\" \" ";
int remaining = 0, count = 0;
do{
position = next_position(string, &remaining);
if(position == -1)
cout << " None Present" << endl;
else
{
cout << " Found At Position " << position << endl;
count++;
}
}while(remaining);
if( count )
{
cout << count << " Found." << endl;
count %= 2;
if( count )
cout << "Mismatched Parenthesis!" << endl;
else
cout << "Parenthesis Match!" << endl;
}
cin.getline();
return 0;
}