ikoasi 2021-04-08 10:51 采纳率: 50%
浏览 29
已采纳

c语言怎么把这里面的warning去掉啊(函数PushStake和函数PopStake)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#define MAX 150 


typedef struct node{
    char date;
    struct node *next;
} LinkStake;

typedef struct node2{
    double date;
    struct node *next;
} Stake;

typedef struct body{
    char date[MAX];
    int j;
} Body;

LinkStake *CreatStake();//建立空栈
int IsEmpty(LinkStake *s);//判断空栈
void Push(char fuhao, LinkStake *s, Body *p);//压栈
int Judge(bool flag, char c);//判断优先级

LinkStake *CreatStake()
{
    LinkStake *s;
    s=malloc(sizeof(struct node));
    s->next = NULL;
    return s;
}

int IsEmpty(LinkStake *s)
{
    return(s->next == NULL);
}

void Push(char fuhao, LinkStake *s, Body *p)
{
    while(s->next != NULL && Judge(false,fuhao)<Judge(true,s->next->date)){
            LinkStake *t;
            printf("%c ", s->next->date);
            p->date[p->j] = s->next->date;
            p->j++;
            t = s->next;
            s->next = t->next;
            free(t);
    }
    if(IsEmpty(s)){
        LinkStake *tmp;
        tmp = malloc(sizeof(struct node));
        tmp->date = fuhao;
        tmp->next = s->next;
        s->next = tmp;
    }
    else if(Judge(false,fuhao)>Judge(true,s->next->date)){
            LinkStake *tmp;
            tmp = malloc(sizeof(struct node));
            tmp->date = fuhao;
            tmp->next = s->next;
            s->next = tmp;
        }
    else if(Judge(false,fuhao) == Judge(true,s->next->date)){
            LinkStake *t;
            t = s->next;
            s->next = t->next;
            free(t);
        }
}

int Judge(bool flag, char c)
{
    if(c == '+' || c == '-')
        if(flag) return 3;
        else return 2;
    else if(c == '*' || c == '/')
        if(flag) return 5;
        else return 4;
    else if(c == '(')
        if(flag) return 1;
        else return 6;
    else if(c == ')')
        if(flag) return 6;
        else return 1;
    else return 0;
}

void PushStake(double c, LinkStake* s)
{
    Stake *tmp;
    tmp = malloc(sizeof(struct node2));
    tmp->date = c;
    tmp->next = s->next;
    s->next = tmp;
}

double PopStake(LinkStake *s)
{
    Stake *t;
    double c;
    t = s->next;
    c = t->date;
    s->next = t->next;
    free(t);
    return c;
}

int main()
{
    int i = 0;
    LinkStake *head;
    Body *p = malloc(sizeof(struct body));
    char s[MAX];
    head = CreatStake();
    p->j = 0;

//    printf("请输入中缀表达式;\n");
    scanf("%s",s);
//    printf("转换为后缀表达式: \n");
    while(s[i]){
        if(s[i]>='0' && s[i]<='9'){
            printf("%c ", s[i]);
            p->date[p->j] = s[i];
            p->j++;
        }
        else Push(s[i],head,p);
        i++;
    }
    while(head->next != NULL){
        printf("%c ", head->next->date);
        p->date[p->j++] = head->next->date;
        p->j++;
        LinkStake *t;
        t = head->next;
        head->next = t->next;
        free(t);
    }
    printf("%c",8);
    printf("\n");

    Stake *stake;
    double sum = 0.0, a, b;
    double sum1=0.0;
    int length;
    length = strlen(s);
    stake = (Stake*)malloc(sizeof(struct node2));
    stake->next = NULL;
    for(i = 0; i < p->j; i++){
        if(p->date[i]>='0' && p->date[i]<='9')
            {
            if(length>1)
            PushStake((double)(p->date[i]-'0'), stake);
            else {
            sum1=p->date[i];
            printf("%.3lf",sum1-'0');goto end;
            }
            }
        else if(p->date[i]=='+'){
            
            if(length>1){
            
            b = PopStake(stake);}
            else b=0;
            a = PopStake(stake);
            sum = a+b;
            PushStake(sum, stake);
        }
         else if(p->date[i]=='-'){
             if(length>1){
            b = PopStake(stake);}
            else b=0;
            a = PopStake(stake);
            sum = a-b;
            PushStake(sum, stake);
        }
         else if(p->date[i]=='*'){
             if(length>1){
            b = PopStake(stake);}
            else b=1;
            a = PopStake(stake);
            sum = a*b;
            PushStake(sum, stake);
        }
         else if(p->date[i]=='/'){
             if(length>1){
            b = PopStake(stake);}
            else b=1;
            a = PopStake(stake);
            sum = a/b;
            PushStake(sum, stake);
        }
    }
    printf("%.3lf", sum);
    end:
    return 0;
}

  • 写回答

5条回答 默认 最新

  • TheXeler 2021-04-08 11:32
    关注

    谢邀,这边建议您先把warning的具体内容贴出来,然后我们逐条分析才好得出结论

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题