【发布时间】:2013-01-18 05:00:07
【问题描述】:
我还没有学过指针,所以当有人问同样的问题时,我不知道其他答案在说什么:S...
while(1)
{
/* intializing variables for the while loop */
temp1 = 0;
temp2 = 0;
val = 0;
for(counter = 0; counter < 256; counter++)
{
input[counter] = ' ';
}
scanf("%s", &input); /* gets user input */
if(input[0] == 'p') /* if user inputs p; program pops the first top element of stack and terminates the loop */
{ /* and the program overall */
printf("%d", pop(stack));
break;
}
if(input[0] == '+' || input[0] == '-' || input[0] == '*') /* if operator is inputted; it pops 2 values and does the arithemetic process */
{
if(stackCounter == 1 || stackCounter == 0) /* If user tries to process operator when there are no elements in stack, gives error and terminates */
{
printf("%s", "Error! : Not enough elements in stack!");
break;
}
else
{
temp1 = pop(stack);
temp2 = pop(stack);
push(stack, arithmetic(temp2, temp1, input[0]));
}
}
else /* if none of the above, it stores the input value into the stack*/
{
val = atoi(input); /* atoi is used to change string to integer */
push(stack, val);
}
}
这是一个使用有限堆栈执行与 postfix 相同操作的程序。其他功能一切正常。当我在 Visual Studio 上编译和运行时,它工作正常,但是当我在 linux(用于测试我的程序)上运行它时,它就不起作用了。它只是给了我:“c:52: warning: char format, different type arg (arg 2)”。
我假设它是导致问题的 scanf 或 atoi 函数...
有没有什么方法可以通过更改几个字母轻松修复这个程序?
【问题讨论】:
标签: c char stack warnings postfix-notation