Help: Storing tokenized 2-digit char (infix->postfix converter)
Hi,
I'm trying to store a tokenized cstring (consisting of a mathematical expression) into a templated char stack. However, when I print the contents of the stack, the char tokens that represented 2-digit int were cut off after the first digit. Here's an example:
Code:
Input: 12 + 14
Output: 1 + 1
I expected this. Can I get help trying to store 2-digit tokens into the stack? Perhaps convert it so I can use the tokens later to calculate in RPN?
Here's the code that stores a cstring into the stack:
Code:
void Stack<E>::str2Stack(char cstring[])
{
char* token;
token = strtok(cstring, " \n");
while (token != NULL)
{
push(*token);
cout<<"Token "<<token<<" pushed"<<endl;
token = strtok(NULL, " \n");
}
}
Thank you!