I'm writing a program in C++ to convert a user-submitted string into a postfix expression and then evaluate it. The function where the string is tokenized into operands, operators and such looks like this:
void Calc::tokenize(char * s){
cout << s << endl;
int i = 0;
char * t = new char[2];
while (i < strlen(s)){
*t = *(s+i);
*(t+1) = '\0';
cout << t;
cout << i << endl;
if (*t == ' '){
i++;
}
cout << t;
//other stuff here
}
I determined from putting cout statements in various places that the program segfaults at the if (*t == ' ') line, but I can't understand why. I was having other problems with this code (apparently with managing parentheses at the point of organizing into postfix, I might ask about that later) but this one is suddenly in the way of everything. Any ideas?