#include<stdio.h> #include<stdlib.h> //头文件 #include<string.h> typedef struct information//定义结构体 { int number; char name[100]; float price; int count; struct information *next; }inf; inf *head; inf *found() //创建信息 { int n; inf *p=NULL,*pre=NULL; //定义指针变量 pre=head=(inf *)malloc(sizeof(inf)); //申请内存 while(1) { p=(inf*)malloc(sizeof (inf)); printf("输入货物的编号、名称、价格、数量:\n"); printf("编号:"); scanf("%d",&p->number); printf("名称:"); scanf("%s",&p->name); printf("价格:"); scanf("%f",&p->price); printf("数量:"); scanf("%d",&p->count); printf("\n"); pre->next=p; pre=p; printf("============================================\n"); printf("是否退出创建货物信息 退出:输1 继续: 输2\n"); scanf("%d",&n); if(n==1) { pre->next=NULL; p=NULL; return head; } printf("\n"); if(n>2) { printf("输入错误!\n"); system("pause"); } } pre->next=NULL; free(p); p=NULL; return head; } void baocun(inf *head) //保存信息 { int h=0; inf *p=NULL; FILE *fp; p=head->next; if(p==NULL) { printf("头结点创建失败!"); } else { p=head->next; if((fp=fopen("货物信息.txt","w"))==NULL) //打开‘货物信息.txt’文件 { printf("不能打开这个文件\n"); exit(0); } fprintf(fp,"编号:%d\t名称:%s\t价格:%f\t数量:%d\n",p->number,p->name,p->price,p->count);//读取信息 while(p!=NULL) { fprintf(fp,"编号:%d\t",p->number); fprintf(fp,"名称:%s\t",p->name); //输出信息 fprintf(fp,"价格:%f\t",p->price); fprintf(fp,"数量:%d\n",p->count); p=p->next; h++; //记录信息数 } printf("保存成功一共%d个货物!\n",h); fclose(fp); } } void find(inf *head) //查询信息 { inf *p=NULL; int d,n; int number1; char n