neil123 发表于 2017-12-10 11:03:07

万能的论坛,请帮我解答这个问题吧

pop函数定义那会报错,说是冲突类型(这是一个逆波兰计算器)
源代码如下:
#include <stdio.h>
#include <math.h>
#include <ctype.h>

#define MAXOP 100
#define NUMBER '0'
#define MAXVAL 100
#define BUFSIZE 100

char buf;
int bufp = 0;
int sp = 0;
double val;

int main(int argc, char *argv[])
{
    char s;
    double op2;

    while(--argc > 0)
    {
      ungets(" ");
      ungets(*++argv);         //把一个空参数和一个参数写入缓冲区
      switch(getop(s))
      {
            case NUMBER:push(atof(s));
                        break;
            case '+':push(pop() + pop());
                     break;
            case '*':push(pop() * pop());
                     break;
            case '-':op2 = pop();
                     push(pop() - op2);
                     break;
            case '/':op2 = pop();
                     if(op2 == 0)
                     {
                         printf("除数不可为零\n");
                     }
                     else
                     {
                         push(pop() / op2);
                     }
                     break;
            default:printf("位置命令%s\n", s);
                  argc = 1;
                  break;
      }
    }

    printf("\t%.8g\n", pop());

    return 0;
}

void push(double f);
void push(double f)
{
    if(sp < MAXVAL)
    {
      val = f;
    }
    else
    {
      printf("栈满,无法入栈%g\n", f);
    }
}

double pop(void);
double pop(void)
{
    if(sp > 0)
    {
      return val[--sp];
    }
    else
    {
      printf("栈为空\n");
      return 0;
    }
}

int getop(char s[]);
int getop(char s[])
{
    int i, c;

    while((s = c = getch()) == ' ' || c == '\t')
    {
      ;
    }
    s = '\0';
    if(!isdigit(c) && c != '.')
    {
      return c;
    }
    i = 0;
    if(isdigit(c))
    {
      while(isdigit(s[++i] = c = getch()))
      {
            ;
      }
    }
    if(c == '.')
    {
      while(isdigit(s[++i] = c = getch()))
      {
            ;
      }
    }
    s = '\0';
    if(c != EOF)
    {
      ungetch(c);
    }
    return NUMBER;
}

int getch(void);
int getch(void)
{
    return (bufp > 0) ? buf[--bufp] : getchar();
}

void ungetch(int c);
void ungetch(int c)
{
    if(bufp >= BUFSIZE)
    {
      printf("以超出最多可承受的字符数量\n");
    }
    else
    {
      buf = c;
    }
}

BngThea 发表于 2017-12-10 11:38:16

函数代码本身没什么问题

neil123 发表于 2017-12-11 09:43:53

BngThea 发表于 2017-12-10 11:38
函数代码本身没什么问题

可是他就是报错了,我也不知道哪里错了

BngThea 发表于 2017-12-11 09:56:31

neil123 发表于 2017-12-11 09:43
可是他就是报错了,我也不知道哪里错了

错误提示?准确一点
页: [1]
查看完整版本: 万能的论坛,请帮我解答这个问题吧