帮忙修改一个小程序

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();
}
...全文
46 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
ShiChao 2003-08-20
  • 打赏
  • 举报
回复
都看不出这个程序是干什么用的啊
skywater 2003-08-20
  • 打赏
  • 举报
回复
Oh my god!
hellobcb 2003-08-20
  • 打赏
  • 举报
回复
这分不好赚啊!除非给500分,帮你看看!
hlnpro 2003-08-20
  • 打赏
  • 举报
回复
晕~~~~~~~~菜
Bandry 2003-08-19
  • 打赏
  • 举报
回复
dddd8888 2003-08-19
  • 打赏
  • 举报
回复
UP
Accelerator 2003-08-19
  • 打赏
  • 举报
回复
/*///////////////////////////////////////////////////////////////////
//改完了,在VC6.0下面编译通过,但是我没有执行过。 //
//说老实话,我不知道这个程序有什么用。 //
//尽量保持程序的原意,但是为了通过编译,不得不擅自加了一些东西。 //
//////////////////////////////////////////////////////////////////*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

#define NULL 0
#define LEN sizeof(struct modi)

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 *create();
struct modi *outstore(struct modi *head,char outmodi);
void outprint(struct modi *head);
void exitfuc();

int main ()
{
char outmodi;
printf("Welcome you! Now, please input the commodity:\n");
printf("If you want to stop input, please input 0!");
modi *head=create();
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();
return 0;
}

struct modi *create()
{
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,char outmodi)
{
int n=LEN;
struct modi *p1,*p2;
char * cat;
if (head==NULL)
{
printf("\nlist null!\n");
goto end;
}
p1=head;
cat=head->cat;
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!",p1->nam);
n=n-1;
}
else
printf("%d not been found in our store!",p2->nam);
end:
return(head);
}



void outprint(struct modi *head)
{
float outnum;
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(0);
}

Accelerator 2003-08-19
  • 打赏
  • 举报
回复
乱死了,格式清楚一点嘛。如果这个就是你的源代码,那么不用细看也知道有问题,例如:
# include "sting.h"
//这个是自定义的头文件吗?

又如:
void outprint(head)
{ struct modi *head;
struct modi *p
printf("category Commodity stock sellnumber profit\n")
p=head;
//这里有俩个句子结束都没有分号

又如:
void exitfuc()
{ exit;}
char outmodi;
printf("Welcome you! Now, please input the commodity:\n");
//第三排后的语句属于函数exitfuc吗?
jack_wq 2003-08-19
  • 打赏
  • 举报
回复
楼主想说明什么?
Smartdoggie 2003-08-19
  • 打赏
  • 举报
回复
哈哈哈哈
亮剑_ 2003-08-19
  • 打赏
  • 举报
回复
楼主:
最好有一些注释说明啊
skywater 2003-08-19
  • 打赏
  • 举报
回复
这是什么玩意?描述一下,好理解一点。

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧