| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 377 人关注过本帖
标题:编译不出来?????
只看楼主 加入收藏
czwx
Rank: 1
等 级:新手上路
帖 子:6
专家分:3
注 册:2015-10-4
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:2 
编译不出来?????
#include<stdio.h>
#include<malloc.h>
struct linklist
{
     int no,price,num;
     struct linklist *next;
};
void create(struct linklist *h)
{   h=NULL;
    int a,b,c;
    struct linklist *p,*q;
    q=h;
    printf("请依次输入商品的编号、单价、数量,以0 0 0作为输入结束的标志\n");
    scanf("%d%d%d",&a,&b,&c);
    while((a!=0)||(b!=0)||(c!=0))
    {   
        p=(struct linklist *)malloc(sizeof(struct linklist));
        p->no =a;
        p->price =b;
        p->num =c;p->next=NULL;
        q->next =p;
        q=p;
        scanf("请继续输入:\n %d%d%d",&a,&b,&c);
    }
 
}
int renew(struct linklist *h)
{    int i;
     struct linklist *p;
     for(p=h;p!=NULL;p=p->next )
     {   
         if(p->no ==1004)
         { for(i=1004;i<1007;i++)
              {
                    p->num =0;
                    p=p->next ;
              }

            return 1;
         }

     }
   
}
int del(struct linklist *h)
{     

   struct linklist *p,*q;
   
   for(p=h;p!=NULL;p=p->next )
   {
      
       if(p->no ==1005)
       {
           q->next =p->next ->next ;
           return 1;
       }
       q=p;
   }
}
int init(struct linklist *h)
{   
    int i=1006;
    struct linklist *p,*q;
    p=h;
    while(p->no !=1004)
        p=p->next ;
    q=(struct linklist *)malloc(sizeof(struct linklist));
    q->no =1005;
    q->num =40;
    q->price =55;
    for(q=q->next ;q!=NULL;q=q->next )
    {   
         q->no =i;
         i++;
    }
    return 1;
}
void collect(struct linklist *h,int *a,int *b)
{
   
    struct linklist *p;
    for(p=h;p!=NULL;p=p->next )
    {
        a=p->num +a;
        b=p->price*p->num  +b;
    }

}
void main()
{
    int a=0,b=0;
    struct linklist *h;
    h=(struct linklist *)malloc(sizeof(struct linklist));
    create(h);
   
    if(renew(h)==1)
        printf("数据已更新\n");
    if(renew(h)==1)
        printf("删除成功\n");
    if(init(h)==1)
        printf("插入成功\n");

    collect(h,&a,&b);
    printf("总数量、总价格为:\n %d    %d",a,b);
}

搜索更多相关主题的帖子: include create price 
2015-10-28 22:44
qq1625127317
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:185
专家分:450
注 册:2015-9-3
收藏
得分:5 
先检查一下你的scanf()中的格式。。。而且我从前辈那里得知一般代码呢,是给别人看的,所以注释一般要占很大一部分篇幅,不然的话就不理解你的函数为什么这样写要具有什么样的功能,我觉得链表的建立函数应该要有返回值的吧。。struct linklist * create(struct linklist *h) 应该是这种形式的吧,函数最后有 return h;
   然后主函数中定义一个头指针head  = create(head),,,应该是这样的,也是新手,请多指教!

静坐常思己过,闲谈莫论人非
2015-10-29 08:04
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9007
专家分:53942
注 册:2011-1-18
收藏
得分:5 
编译失败,为什么不贴出编译器给出的错误信息?
别人用的编译器(包括编译器设置)可能和你不一样,你不贴出编译器给出的信息,别人怎么知道哪句报什么错?

我这里编译通过,但有三个警告
第一个说 renew 函数不是所有路径都有返回
第二个说 del 函数不是所有路径都有返回
第三个说 你写的main函数返回类型不是int
2015-10-29 08:19
快速回复:编译不出来?????
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023165 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved