unexpected end of file found

shdxu 2006-10-30 01:18:31
#include "stdlib.h"
#include "string.h"
#include "iostream.h" #include "stdafx.h" #define MAX 100
typedef struct //声明堆栈结构
{
int stack[MAX]; //栈顶指针
int top; //栈顶数据
}sqstack;
sqstack operator,operand;
//存入堆栈数据
int push(sqstack *s,int value)
{
if(s->top=MAX-1)
return 0;
s->top++;
s->stack[s->top]=value;
return 1;
}
//从堆栈中取出数据
int pop(sqstack *s)
{
int x;
if(s->top<0)
return NULL;
x=s->stack[s->top];
s->top--;
return x;
}
//检查堆栈是否为空
int empty(sqstack *s)
{
if(s->top<0)
return 1;
else
return 0;
}
//判断是否为运算符
int is_oprator(char operator)
{
switch(operator) //operator是运算符
case '+': case'-': case '*': case '/':
return 1;
default:
return 0;
}
//判断运算符的优先权
int priority(char operator)
{
switch(operator)
{
case '+': case'-':
return 1;break;
case '*': case '/':
return 2;break;
default:return 0;
}
}
//计算任意两个操作数的值
int two_result(int operator,int operand1,int operand2)
{
switch(operator)
{
case '+':return (operand1+operand2);
case '-':return (operand1-operand2);
case '*':return (operand1*operand2);
case '/':return (operand1/operand2);
}
}
//主程序,输入中序表达式后计算出表达式的结果值
void main()
{
char expreession[100];
int position=0;
int op=0;
int operand1=0;
int operand2=0;
operator->top=operand->=-1;
cout<<endl;
cout<<"Please input the inorder expression:";
gets(expression);
while(expression[position]!='\0'&&expression[position]!='\n')
{
if(is_operator(expression[position]))
{
if(!empty(oparetor))
while(priority(expression[position])<=priorty(operator->data)&&!empty(operator))
{
operand1=pop(operand);
operand2=pop(operand);
op=pop(operator);
oprand=push(operand,two_result(op,operand1,operand2);
}
operator=push(operator,expression[position]);
}
else
operand=push(operand,expression[position]-48);
position++;
}
while(!empty(operator))
{
op=pop(operator);
oprand1=pop(operand);
oprand2=pop(operand);
operand=push(operand,two_result(op,operand1,operand2));
}
evaluate=pop(operand);
cout<<"The expression["+expression+"] result is '"+evaluate+"'"<<endl;
}

求中序表达式程序
运行出现unexpected end of file found错误
...全文
276 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
飞哥 2006-10-30
  • 打赏
  • 举报
回复
未匹配括号
或者 #include"stdafx.h
这个预编译头文件未找到,或者没有指定使用预编译"
springlie 2006-10-30
  • 打赏
  • 举报
回复
同楼上
一般是缺少分号或者括号
morphymorphy 2006-10-30
  • 打赏
  • 举报
回复
这个错误的说明在MSDN中有,主要还是仔细看一下程序,找一下语法错误。
检查:括号是否匹配,函数调用参数是否匹配,在类定义后要有分号,检查注释标记是否匹配,检查条件编译符号(#IF。。#ENDIF是否匹配),再有看一下磁盘空间是否够大,在空间不够,不能正常编译。

shdxu 2006-10-30
  • 打赏
  • 举报
回复
#include "stdlib.h"
#include "string.h"
#include "iostream.h"
#define MAX 100

typedef struct //声明堆栈结构
{
int stack[MAX]; //栈顶指针
int top; //栈顶数据
}sqstack;
sqstack operator,operand;
//存入堆栈数据
int push(sqstack *s,int value)
{
if(s->top=MAX-1)
return 0;
s->top++;
s->stack[s->top]=value;
return 1;
}
//从堆栈中取出数据
int pop(sqstack *s)
{
int x;
if(s->top<0)
return NULL;
x=s->stack[s->top];
s->top--;
return x;
}
//检查堆栈是否为空
int empty(sqstack *s)
{
if(s->top<0)
return 1;
else
return 0;
}
//判断是否为运算符
int is_oprator(char operator)
{
switch(operator) //operator是运算符
case '+': case'-': case '*': case '/':
return 1;
default:
return 0;
}
//判断运算符的优先权
int priority(char operator)
{
switch(operator)
{
case '+': case'-':
return 1;break;
case '*': case '/':
return 2;break;
default:return 0;
}
}
//计算任意两个操作数的值
int two_result(int operator,int operand1,int operand2)
{
switch(operator)
{
case '+':return (operand1+operand2);
case '-':return (operand1-operand2);
case '*':return (operand1*operand2);
case '/':return (operand1/operand2);
}
}
//主程序,输入中序表达式后计算出表达式的结果值
void main()
{
char expreession[100];
int position=0;
int op=0;
int operand1=0;
int operand2=0;
operator->top=operand->=-1;
cout<<endl;
cout<<"Please input the inorder expression:";
gets(expression);
while(expression[position]!='\0'&&expression[position]!='\n')
{
if(is_operator(expression[position]))
{
if(!empty(oparetor))
while(priority(expression[position])<=priorty(operator->data)&&!empty(operator))
{
operand1=pop(operand);
operand2=pop(operand);
op=pop(operator);
oprand=push(operand,two_result(op,operand1,operand2);
}
operator=push(operator,expression[position]);
}
else
operand=push(operand,expression[position]-48);
position++;
}
while(!empty(operator))
{
op=pop(operator);
oprand1=pop(operand);
oprand2=pop(operand);
operand=push(operand,two_result(op,operand1,operand2));
}
evaluate=pop(operand);
cout<<"The expression["+expression+"] result is '"+evaluate+"'"<<endl;
}

程序是这个,不是上面的

64,687

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧