下面的代码是一个简单的postfix计算程序。尽管没有-Wall选项,代码工作得非常好,但我似乎无法找到为什么它不能使用该选项。我有一个模糊的想法 - 墙不允许我使用默认的signed char数组。因此,根据错误讯息,postfix2.c: In function ‘main’: postfix2.c:45:3: warning: array subscript has type ‘char’
我尝试声明unsigned char input[13]
。它没有解决这个问题。任何关于-Wall概念的指针,以及错误可能在哪里?谢谢。哦,让我自己纠正代码,不要简单地给我固定的代码!使用gcc -Wall给出的数组下标有'char'类型的错误
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define _CRT_SECURE_NO_DEPRECATE
int stack[100];
int top;
void push(int x){
top++;
stack[top] = x;
}
int pop(){
int temp = stack[top];
top--;
return(temp);
}
int main()
{
char input[13];
int integer, a, b, result;
while(1){
scanf("%s", input);
if (isdigit(input[0])) {
integer = atoi(input);
push(integer);
}
if (input[0] == '+'){
b = pop();
a = pop();
push (a+b);
}
else{
if (input[0] == '-'){
b = pop();
a = pop();
push (a-b);
}
else{
if (input[0] == '*'){
b = pop();
a = pop();
push (a*b);
}
}
}
if (input[0] == 'p'){
result = pop();
printf("%d\n", result);
}
}
}
这不是真正的代码。 – cnicutar
先提供真实码 –
我看到我贴的代码。你们不看代码吗?我应该发布一个主要链接吗? –