#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define MAX_STACK_SIZE 100
#define MAX_EXPRESSION 100
#define END_OF_INPUT '#'
int stack[MAX_STACK_SIZE];
int top = 1;
void push(int item)
{
if(top >= (MAX_STACK_SIZE-1))
{
printf("stack is full");
return;
}
}
int pop()
{
if(top == -1)
{
printf("stack is empty");
exit(0);
}
return stack[top--];
}
eval(char exp[])
{
int op1, op2;
int value;
char ch;
int i = 0;
while((ch = exp[i++]) != END_OF_INPUT)
{
if(ch != '+' && ch != '-' && ch != '*' && ch != '/')
{
value = ch - '0';
push(value);
}
// 입력이 연산자이면 피연산자를 스택에서 제거
//연산을 수행하고 결과를 스택에 저장
else
{
op2 = pop();
op1 = pop();
switch(ch)
{
case '+':push(op1+op2);break;
case '-':push(op1-op2);break;
case '*':push(op1*op2);break;
case '/':push(op1/op2);break;
}
}
}
return pop();
}
void main()
{
int result;
printf("후위표기식은 82/3-32*+#\n");
result = eval("82/3-32*+#");
printf("결과값은 %d\n", result);
getch();
}
이 소스인데요. 에러는 없는데 실행할때 다음 화면과 같은 메세지가 뜹니다.
왜 저런메세지 뜨는지 좀 알고싶습니다. vc소스라서 그런지 vc에서는 잘돌아가더군요.
|