【求助】①error C2059: syntax error : 'type' ② error C2065: 'result' : undeclared
篱落~ 2019-04-24 07:52:17 #include<stdio.h>
#include<malloc.h>
#include<stdlib.h> //包含exit()函数
#include<ctype.h> //包含isdigit()函数
typedef int datatype; //定义datatype为int
#include"linstack.h" //包含linstack.h头文件
int postexp(char str[])
//借助堆栈计算后缀算术表达式str的值
{
datatype x,x1,x2;
int i;
lsnode *head; //定义头指针变量head
stackinitiate(&head); //初始化链式堆栈head
for(i=0;str[i]!='#';i++)
{
if(isdigit(str[i])) //当str[i]为操作数时
{
x=(int)(str[i]-48); //转换成int类型数据并存入变量x中
stackpush(head,x); //x入栈
}
else //当str[i]为运算符时
{
stackpop(head,&x2); //退栈得到操作数,存入变量x2中
stackpop(head,&x1); //退栈得到被操作数,存入变量x1中
switch(str[i])
{
case '+':{x1+=x2;break;}
case '-':{x1-=x2;break;}
case '*':{x1*=x2;break;}
case '/':
if(x2==0.0)
{
printf("除数为0错!\n");
exit(0);
}
else
{
x1/=x2;
break;
}
}
stackpush(head,x1); //运算结果入栈
}
}
stackpop(head,&x); //得到计算结果,存入x中
return x;
}
void main(void)
{
char str[]="3642/-5*+#", //测试数据
int result;
result=postexp(str);
printf("后缀算术表达式计算结果为:%d",result);
}
这是我按照课本写的程序代码,用VC++编写的,编译后提示有一条错误。
自己改了好久也没有解决,所以来请教各位大佬!
Compiling...
3-4.c
D:\数据结构\3-4.c(51) : error C2059: syntax error : 'type'
D:\数据结构\3-4.c(52) : error C2065: 'result' : undeclared identifier
执行 cl.exe 时出错.