Я делаю простую программу преобразования из инфикса в постфикс, но после ввода полученного выражения постфикса числа появляются в виде вопросительных знаков в полях. Что мне делать, чтобы на выходе были числа?
Я не знаю, какая часть кода вызывает эту проблему.
bool convert(char inf[], char post[])
{
char term;
int i, k, length, oprn;
nd top;
top = createStack();
length = strlen(inf);
for(i=0, k=-1; i<length; i++)
{
term = inf[i];
if(isdigit(term))
{
oprn = term - '0';
post[++k] = oprn;
}
else if (term == '(')
{
push(&top,term);
}
else if (term == ')')
{
bool empty;
empty = isEmpty(top);
while(!empty && peek(top) != '(')
post[++k] = pop(&top);
if(!empty && peek(top) != '(')
return -1; //the expression is not valid
else
pop(&top);
}
else //if term is an operator
{
bool empty;
empty = isEmpty(top);
if(empty){
push(&top,term);}
else
{
while(!empty && prec(term)<=prec(peek(top)))
post[++k] = pop(&top);
push(&top,term);
}
}
}//end of for loop
while(!isEmpty(top))
post[++k] = pop(&top);
post[++k] = '\0';
}
Я вызвал функцию, используя это в main
int main(void)
{
bool ok;
char inFix[s];
char postFix[s]="";
getInfix(inFix);
ok = convert(inFix,postFix);
if(ok)
{
printf("\n\nThe resulting postfix expression is: ");
puts(postFix);
}
else
{
printf("\n\nAn error has occurred...");
}
getch();
return 0;
}