我正在实施算术计算器,但我收到错误:
错误:')'令牌之前的预期primary-expression 错误:' - >'之前的预期primary-expression令牌
我发布了包含错误的行。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/*creating stack*/
typedef struct stack
{
int top;
char *array;
int max_size;
}S;
/*pushing character to it*/
void push(S *st ,char ch)
{
if(st->top==st->max_size)
{printf("already full..delete some items :)");return ;}
printf("st->top=%d ",st->top);
strcpy(&st->array[st->top],&ch);
st->top++;
printf("push=%s ",st->array[st->top-1]);
}
/*deleting character*/
void pop(S *st)
{
if(st->top==0)
{printf("it's empty..push some items :)");return ;}
st->top--;
}
void fun(S *stack,S *post,char a)
{
while(strcmp((&stack->array[stack->top]),&a)!=0)
{
pop(stack);
push(post,stack->array[stack->top+1]);
}
pop(stack);
}
int main()
{
int i,j;
char str[10000];
/*initialize 3 stacks*/
S *st =init(10000);
S *post=init(10000);
S *ans=init(10000);
/ *actually code is very big so i am
giving only lines in which there is error*/
//some code...
fun(stack,post,a);
//some code...
while(precedence(str[i])>precedence(stack->array[stack->top]))
//some code...
push(post,stack->array[stack->top]);
pop(stack);
//more code......
}
答案 0 :(得分:3)
您的结构和变量名称相同stack
。这非常糟糕,让您和编译器感到困惑。使用大写字母表示结构/类名。
答案 1 :(得分:1)
在void fun(S *stack,S *post,char a)
功能中,您正在使用
strcmp((&stack->array[stack->top]),&a)!=0
比较两个char
。 strcmp()
用于比较字符串,因此请改用:
stack->array[stack->top] != a