下面是一段简单计算器的C语言代码,有些问题,请高手帮忙下!

来源:百度知道 编辑:UC知道 时间:2024/06/18 01:18:09
#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>
#include<math.h>

#define MAXOP 100
#define NUMBER 0
#define TRUE 1
#define FALSE 0
#define IDENTIFIER 1
#define MAXVAL 100
int sp = 0;
double val[MAXVAL];
int Getop(char s[]);
void push(double val);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();
void dealWithName(char s[])
int main(void)
{int type;
double op2,op3;
char s[MAXOP];
int flag = TRUE;
while((type = Getop(s)) != EOF){
switch(type)
{case NUMBER:
push(atof(s));
break;
case IDENTIFIER:
dealWithName(s);
break;
case '+':
push(pop() + pop());
break;
case '*':
push(pop() * pop());
break;
case '-':
op2 = pop();
push(pop()- op2);
break;
case '/

程序是正确的,dealWithName(s)这个函数逻辑上没错,你试下是不是你的输入出错

#include<stdlib.h>
#include<stdio.h>
#include<ctype.h>
#include<math.h>

#define MAXOP 100
#define NUMBER 0
#define TRUE 1
#define FALSE 0
#define IDENTIFIER 1
#define MAXVAL 100
int sp = 0;
double val[MAXVAL];
int Getop(char s[]);
void push(double val);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();
void dealWithName(char s[]);//这里少了分号
int main(void)
{int type;
double op2,op3;
char s[MAXOP];
int flag = TRUE;
while((type = Getop(s)) != EOF){
switch(type)
{case NUMBER:
push(atof(s));
break;
case IDENTIFIER:
dealWithName(s);
break;
case '+':
push(pop() + pop());
break;
case '*':
push(pop() * pop());
break;
case '-':
op2 = pop();