收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 我的程序怎么改才能将输入的数据保存呢,要求下一次打开还是看到数据.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define MaxSize 50
typedef struct chain
{
int number;
char name[MaxSize];
float price;
int count;
int pnum;
int pprice;
int pcount;
struct chain *p,*q;
}DLL;
DLL *head=NULL;
void show_one(DLL *n) /* 输出一条记录 */
{
printf("%d\t%s\t%f\t%d\n", n->number, n->name, n->price,n->count);
}
void show() /* 输出所有记录 */
{
DLL *h=head;
if(head==NULL)
{
return;
}
while (h)
{
show_one(h);
h=h->q;
}
}
int insert()
{
DLL *h=head,*n;
n=(DLL *)malloc(sizeof(DLL));
n->p=NULL;
n->q=NULL;
printf("请输入产品编号:");
scanf("%d", &n->number);
printf("请输入产品名称:");
scanf("%s", n->name);
printf("请输入产品价格:");
scanf("%f",&n->price);
printf("请输入产品数量:");
scanf("%d", &n->count);
if(head==NULL)
{
head=n;
return 1;
}
while(h)
{
if(h->number > n->number)
{
if(h->p)
h->p->q=n;
n->p=h->p;
h->p=n;
if(h->q)
h->q->p=n;
n->q=h;
return 1;
}
else if(h->number==n->number)
{
free(n);
return 0;
}
if (!h->q)
{
h->q=n;
n->p=h;
return 1;
}
h=h->q;
}
return 1;
}
void initial()
{
while (1)
{
printf("\n\n\n\n\n\n\n\n\n\-------------------------欢迎来到库存管理系统,按y进入主菜单-------------------\n");
if(getch()==121)
break;
}
}
int delet()
{
int num;
DLL *h=head;
printf("请输入要删除产品的编号:");
scanf("%d", &num);
if(head==NULL)
{
return 0;
}
while(h)
{
if(h->number==num)
{
if(h->p)
h->p->q=h->q;
if(h->q)
h->q->p=h->p;
if(h==head)
{
head=h->q;
free(h);
return 1;
}
}
h=h->q;
}
return 0;
}
int update()
{
int num, counter;
DLL *h= head;
printf("请输入要修改产品的编号:");
scanf("%d", &num);
printf("请输入要修改产品的数量:");
scanf("%d", &counter);
if(head==NULL)
{
return 0;
}
while(h)
{
if(h->number == num)
{
if (counter==0)
{
if(h->p)
h->p->q=h->q;
if(h->q)
h->q->p=h->p;
head=h->q;
free(h);
return 1;
}
h->count=counter;
return 1;
}
h=h->q;
}
return 0;
}
void search()
{
int num;
DLL *h=head;
printf("请输入要查找产品的编号:");
scanf("%d", &num);
if(head==NULL)
{
return;
}
while (h)
{
if(h->number==num)
{
show_one(h);
return;
}
h=h->q;
}
}
void search_name()
{
char name[MaxSize];
DLL *h=head;
printf("请输入要查找产品的名称:");
scanf("%s", name);
if(head==NULL)
{
return;
}
while(h)
{
if(!strcmp(h->name,name))
show_one(h);
h=h->q;
}
}
int main()
{
initial();
while (1)
{
char ch;
system("cls");
printf("------------------------------------------\n");
printf("------------------------------------------\n");
printf("------------------------------------------\n");
printf("------------------------------------------\n");
printf("------------------------------------------\n");
printf("\t\t\t\ti 增加新货物\n");
printf("\t\t\t\td 删除某种货物\n");
printf("\t\t\t\ta 修改某种货物的数量\n");
printf("\t\t\t\ts 查找指定的货物\n");
printf("\t\t\t\to 输出存货信息\n");
printf("\t\t\t\tq 保存并退出程序\n");
printf("------------------------------------------\n");
printf("------------------------------------------\n");
printf("----------------------------------信管0901班----------------------------------\n");
printf("------------------------------------------\n");
printf("------------------------------------------\n");
printf("-------------------------------------邹翔-------------------------------------\n");
ch=getch();
switch (ch)
{
case 'i':
case 'I':
insert();
break;
case 'd':
case 'D':
delet();
break;
case 'a':
case 'A':
update();
break;
case 's':
case 'S':
printf("1. 按编号查找\n2. 按名称查找\n");
ch = getch();
if(ch == '1')
{
search();
}
else if(ch == '2')
{
search_name();
}
break;
case 'o':
case 'O':
show();
break;
case 'q':
case 'Q':
return 0;
break;
}
printf("按任意键返回主菜单...");
getch();
}
return 0;
}
[解决办法]
邹翔 信管0901班