帮忙修改一个小程序
ppv 2003-08-19 02:43:53 # include "stdio.h"
# include "math.h"
# include "sting.h"
# define null 0
# define len sizeof (struct modi)
main ()
{ struct modi
{ char cat[10];
char nam[40];
char prodsite[20];
char indate[10];
float inprice;
float outprice;
float prenum;
float innum;
float stocknum;
struct modi *next;
};
struct modi *instore()
{ struct modi *head;
struct modi *p1,*p2;
int n=0;
p1=p2=(struct modi *)malloc(len);
scanf("%d,%d,%d,%d,%f,%f,%f,%f,%f",&p1->cat,&p1->nam,&p1->prodsite,&p1->indate,
&p1->inprice,&p1->outprice,&p1->prenum;&p1->innum;&p1->stocknum);
head=null;
while (p1->cat!=0)
{
n+=1;
if (n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct modi *)malloc(len);
scanf("%d,%d,%d,%d,%f,%f,%f,%f,%f",&p1->cat,&p1->nam,&p1->prodsite,&p1->indate,
&p1->inprice,&p1->outprice,&p1->prenum;&p1->innum;&p1->stocknum);
}
p2->next=null;
return(head);
};
struct modi *outstore()
{ struct modi *head;
struct modi *p1,*p2;
if (head==null)
{printf("\nlist null!\n";goto end;}
p1=head;
while (cat!=p1->cat&&p1->next!=null)
{p2=p1;p1=p1->next}
if (cat==p1->cat)
{if (p1==head)
head=p1->next;
else
p2->next=p1->next;
printf("Now %d has been sold!",nam);
n=n-1; }
else
printf("%d not been found in our store!",nam);
end:
return(head);
};
void outprint(head)
{ struct modi *head;
struct modi *p
printf("category Commodity stock sellnumber profit\n")
p=head;
if (head!=null)
do
{outnum=(p->stocknum-p->prenum)
float profit=outnum*(p->outprice-p->inprice)
printf("%d%d%f%f%f\n",p->cat,p->nam,p->stocknum,outnum,profit);
p=p->next;}
while (p!=null);
}
void exitfuc()
{ exit;}
char outmodi;
printf("Welcome you! Now, please input the commodity:\n");
printf("If you want to stop input, please input 0!");
head=creat();
printf("Please input the name be sold:\n");
scanf("%d",&outmodi);
head=outstore(head,outmodi);
printf("Now, The system will print the list of commodity in store:\n");
outprint(head);
exitfuc();
}