编译不出来?????
#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);
}