This is a task which was said to be easy, but hours went, I'm still here...
I'm dealing with the char array in the stack. I need to reverse the chars except for those in double quotes.
If the line has quotes, then my program would fail. I do have trouble outputing the chars in the array in its original order. Appreciate for any help...
---------------------------------------
// read on char at a time, put it in Stack1
//
for (int i = 0; i < size; i++)
{
switch (state) {
case reverseLine:
if ( A[i] == ' ' || A[i] == '\t' ) {
;
}
else if ( A[i] != '\"') {
pushStack(Stack1, A[i]);
cout << "No Quote!" << endl;
//cout << popStack(Stack1) <<endl;
state = reverseLine;
}
else {
pushStack(Stack1, A[i]);
//cout << popStack(Stack1);
state = QuoteWords;
}
//cout << "I'm here!";
//cout << popStack(Stack1) << endl;
break;
//!!!MY BIG PROBLEM IN THIS STATE
case QuoteWords:
if ( A[i] != '\"') {
//cout << "QuoteWords!" << endl;
cout << A[i];
state = QuoteWords;
}
else if ( popStack(Stack1) == '\"') {
pushStack(Stack1, A[i]);
cout << popStack(Stack1);
state = reverseLine;
}
else
state = QuoteWords;
break;
}
}
for (int i=0;i < size; i++)
cout << popStack(Stack1) << endl;
}
-------------------------------------------
ex. input: happy "day" one
output should be eno "day" yappy