主题:错进行了函数调用但不知怎么改
是关于超市的小票系统的,输入,输出及查询。各位高手高高手帮忙看一下吧,长是长了点
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <conio.h>
#define M 30
#define N 10000
struct Lnode
{
char code[20];
char name[80];
float price;
Lnode *next;
};
typedef Lnode *SqList;
float sum = 0;
int goodnum = 0;
int NUMBER[N];
char str[N][80];
int Listname(char str[][80], char name[]);
void Listrecord(SqList &L);
void Listsearch(SqList L, char code2[]);
void Listfoundinformation(SqList &L);
void Listsert(SqList &L);
void ListDelete(SqList &L, char code[]);
void ListDelete2(SqList &L, char code[]);
void Listpint(SqList &L);
void Listallpint(SqList L);
void main()
{
char code2[20];
char ch;
SqList L;
int x, s;
printf("Please input the information of the good:\n");
while(1) //输入初始商品信息
{
Listfoundinformation(L);
printf("Do you want to continue(YES 1 or NO 0):");
scanf("%d", &s);
if(s==0)
break;
}
printf("output print 1 or 0 :");// 查找商品信息
ch = getchar();
while (ch == '1')
{
printf("please input the good's code:");
scanf("%s", code2);
Listsearch(L, code2);
printf("if you want to continue please 1 ,other 0:");
ch = getchar();
}
system("cls");
printf("if you want to delete good information(input 1 or 0):");//删除商品信息
scanf("%d", &x);
while (x == 1)
{
printf("\ninput code:");
scanf("%s", code2);
ListDelete(L, code2);
}
printf("\nif want to insert the good information 1 0r 0:");//插入商品信息
scanf("%d", &x);
while(x == 1)
{
Listsert(L);
printf("\nCONTINUE OR NOT(1 or 0):");
scanf("%d", &x);
}
printf("\nif you want to sell the good please input 1 other 0 :");//出售商品系统
ch = getchar();
if(ch == '1')
Listpint(L);
system("cls");
printf("if you want to print the all information(1 or 0):");//商品总货清单
scanf("%d", &x);
if(x == 1)
Listallpint(L);
printf("if you want to record the information please input 1 or 0:");//信息入文件
scanf("%d", &x);
if(x == 1)
Listrecord(L);
system("cls");
}
void InitList(SqList &L)
{
Lnode *head;
head = new struct Lnode;
if(head == NULL)
{
printf("the memory is not enough!\n");
return;
}
else
{
head->next = NULL;
}
}
void Listfoundinforation(SqList &L)
{
char name[80];
char code[20];
int i;
float price;
Lnode *pnew, *p;
printf("please input the code:");
scanf("%s", code);
printf("\nplease input the name:");
scanf("%s" , name);
fflush(stdin);
printf("\nplease input the price:");
scanf("%d", &price);
pnew = new struct Lnode;
if(pnew == NULL)
{
printf("the room is not enough");
return;
}
strcpy(pnew->code , code);
strcpy(pnew->name , name);
pnew->price = price;
p = L;
while(p->next != NULL)
p = p->next;
p->next = pnew;
pnew->next = NULL;
i = Listname(str, name);
if(i > N)
{
NUMBER[i++]++;
}
else
NUMBER[i]++;
Listrecord(L);
}
void Listsert(SqList &L)
{
char name[80];
char code[20];
float price;
int i;
Lnode *pnew, *p;
printf("CODE:");
scanf("%s",code);
printf("\nNAME:");
scanf("%s", name);
fflush(stdin);
printf("\nPRICE:");
scanf("%d", &price);
pnew = new struct Lnode;
if(pnew = NULL)
{
printf("\nthe memory is not enough!");
}
strcpy(pnew->code , code);
strcpy(pnew->name , name);
pnew->price = price;
p = L;
while(p->next)
{
p = p->next;
}
p->next = pnew;
pnew->next = NULL;
i = Listname(str, name);
NUMBER[i]++;
}
void Listsearch(SqList L, char code2[])
{
int i;
char name[80];
Lnode *q;
for(q = L; q->next!=NULL;q = q->next)
if(strcmp(q->code, code2) == 0)
break;
strcpy(name, q->name);
i = Listname(str, name);
if(q->next == NULL)
{
printf("the good is not exist\n");
return;
}
printf("编号 名称 价格 数量\n");
printf("%-10c%-10c%-10d%-10f.2\n", q->code, q->name, q->price, NUMBER[i]);
printf("------------------------------------------------------------------\n");
printf("\n");
if(NUMBER[i] < M)
{
printf("the good is not enough!");
}
}
int Listname(char str[][80], char name[])
{
int i = 0;
while((strcmp(str[i] , name)!= 0) )
i++;
return (i);
}
void ListDelete(SqList &L, char code[])
{
Lnode *q , *h;
int i;
q = L;
h = q->next;
while(h->code != code)
{
q = q->next;
h = q ->next;
}
i = Listname(str, h->name);
if(i == -1)
{
printf("the code is not exist!\n");
return;
}
NUMBER[i]--;
free(h);
}
void ListDelete2(SqList &L, char code[])
{
int i;
Lnode *q , *p;
q = L;
p = q->next;
while(q->next->code != code)
{
q = q->next;
p = q ->next;
}
i = Listname(str, p->name);
NUMBER[i]--;
printf("%-10c%-10d%-10f.2\n", p->name, p->price, NUMBER[i]);
printf("\n");
sum += p->price;
goodnum++;
q->next = p->next;
free(p);
}
void Listpint(SqList &L)//进行商品销售
{
int x = 1;
char code[20];
printf("\t\t\t\t\t编号 名称 价格 数量\n");
while(x)
{
printf("编号:");
scanf("%s", code);
ListDelete2(L, code);
printf("\ncontinue or not (1 or 0):");
scanf("%d", &x);
}
printf("the sum price of all goods is %f \n", sum);
printf("the number of the goods is %d \n", goodnum);
}
void Listrecord(SqList &L)//退出并把数据写入文件//
{
FILE *fp;
Lnode *pnew;
fp = fopen("data.txt","w");
if(fp == NULL)
{
printf("can not open the file!\n");
exit(0);
}
for(pnew=L->next;pnew!=NULL;pnew=pnew->next)
{
if(pnew->next!=NULL)
{
fputs (pnew->name, fp);
fputs ("\n",fp);
fprintf(fp,"%f",pnew->price);
fputs ("\n",fp);
fprintf(fp,"%s",pnew->code);
fputs ("\n",fp);
}
else
{
fputs(pnew->name, fp);
fputs("\n", fp);
fprintf(fp, "%f", pnew->price);
fputs("\n", fp);
fprintf(fp,"%s", pnew->code);
fputs("\n", fp);
fclose(fp);
}
}
}
void Listallprint(SqList L)
{
FILE *fp;
Lnode *q;
int i;
q = L->next;
printf("编号 名称 价格 数量\n");
while(q->next != NULL)
{
i = Listname(str, q->name);
printf("%-10c%-10c%-10.2f%-10d\n", q->code, q->name, q->price, NUMBER[i]);
printf("------------------------------------------------------------------\n");
printf("\n");
}
printf("\n");
printf("\n");
printf("\n");
printf("\t\t\t\t商品存货信息");
printf("------------------------------------------------------");
q = L->next;
while(q->next != NULL)
{
i = Listname(str,q->name);
if(i < M)
printf("the good of %d is not enough ,please buy some\n", str[i]);
}
fp = fopen("data.text", "r");
if(fp == NULL)
{
printf("can not open the file!");
exit(0);
}
fclose(fp);
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <conio.h>
#define M 30
#define N 10000
struct Lnode
{
char code[20];
char name[80];
float price;
Lnode *next;
};
typedef Lnode *SqList;
float sum = 0;
int goodnum = 0;
int NUMBER[N];
char str[N][80];
int Listname(char str[][80], char name[]);
void Listrecord(SqList &L);
void Listsearch(SqList L, char code2[]);
void Listfoundinformation(SqList &L);
void Listsert(SqList &L);
void ListDelete(SqList &L, char code[]);
void ListDelete2(SqList &L, char code[]);
void Listpint(SqList &L);
void Listallpint(SqList L);
void main()
{
char code2[20];
char ch;
SqList L;
int x, s;
printf("Please input the information of the good:\n");
while(1) //输入初始商品信息
{
Listfoundinformation(L);
printf("Do you want to continue(YES 1 or NO 0):");
scanf("%d", &s);
if(s==0)
break;
}
printf("output print 1 or 0 :");// 查找商品信息
ch = getchar();
while (ch == '1')
{
printf("please input the good's code:");
scanf("%s", code2);
Listsearch(L, code2);
printf("if you want to continue please 1 ,other 0:");
ch = getchar();
}
system("cls");
printf("if you want to delete good information(input 1 or 0):");//删除商品信息
scanf("%d", &x);
while (x == 1)
{
printf("\ninput code:");
scanf("%s", code2);
ListDelete(L, code2);
}
printf("\nif want to insert the good information 1 0r 0:");//插入商品信息
scanf("%d", &x);
while(x == 1)
{
Listsert(L);
printf("\nCONTINUE OR NOT(1 or 0):");
scanf("%d", &x);
}
printf("\nif you want to sell the good please input 1 other 0 :");//出售商品系统
ch = getchar();
if(ch == '1')
Listpint(L);
system("cls");
printf("if you want to print the all information(1 or 0):");//商品总货清单
scanf("%d", &x);
if(x == 1)
Listallpint(L);
printf("if you want to record the information please input 1 or 0:");//信息入文件
scanf("%d", &x);
if(x == 1)
Listrecord(L);
system("cls");
}
void InitList(SqList &L)
{
Lnode *head;
head = new struct Lnode;
if(head == NULL)
{
printf("the memory is not enough!\n");
return;
}
else
{
head->next = NULL;
}
}
void Listfoundinforation(SqList &L)
{
char name[80];
char code[20];
int i;
float price;
Lnode *pnew, *p;
printf("please input the code:");
scanf("%s", code);
printf("\nplease input the name:");
scanf("%s" , name);
fflush(stdin);
printf("\nplease input the price:");
scanf("%d", &price);
pnew = new struct Lnode;
if(pnew == NULL)
{
printf("the room is not enough");
return;
}
strcpy(pnew->code , code);
strcpy(pnew->name , name);
pnew->price = price;
p = L;
while(p->next != NULL)
p = p->next;
p->next = pnew;
pnew->next = NULL;
i = Listname(str, name);
if(i > N)
{
NUMBER[i++]++;
}
else
NUMBER[i]++;
Listrecord(L);
}
void Listsert(SqList &L)
{
char name[80];
char code[20];
float price;
int i;
Lnode *pnew, *p;
printf("CODE:");
scanf("%s",code);
printf("\nNAME:");
scanf("%s", name);
fflush(stdin);
printf("\nPRICE:");
scanf("%d", &price);
pnew = new struct Lnode;
if(pnew = NULL)
{
printf("\nthe memory is not enough!");
}
strcpy(pnew->code , code);
strcpy(pnew->name , name);
pnew->price = price;
p = L;
while(p->next)
{
p = p->next;
}
p->next = pnew;
pnew->next = NULL;
i = Listname(str, name);
NUMBER[i]++;
}
void Listsearch(SqList L, char code2[])
{
int i;
char name[80];
Lnode *q;
for(q = L; q->next!=NULL;q = q->next)
if(strcmp(q->code, code2) == 0)
break;
strcpy(name, q->name);
i = Listname(str, name);
if(q->next == NULL)
{
printf("the good is not exist\n");
return;
}
printf("编号 名称 价格 数量\n");
printf("%-10c%-10c%-10d%-10f.2\n", q->code, q->name, q->price, NUMBER[i]);
printf("------------------------------------------------------------------\n");
printf("\n");
if(NUMBER[i] < M)
{
printf("the good is not enough!");
}
}
int Listname(char str[][80], char name[])
{
int i = 0;
while((strcmp(str[i] , name)!= 0) )
i++;
return (i);
}
void ListDelete(SqList &L, char code[])
{
Lnode *q , *h;
int i;
q = L;
h = q->next;
while(h->code != code)
{
q = q->next;
h = q ->next;
}
i = Listname(str, h->name);
if(i == -1)
{
printf("the code is not exist!\n");
return;
}
NUMBER[i]--;
free(h);
}
void ListDelete2(SqList &L, char code[])
{
int i;
Lnode *q , *p;
q = L;
p = q->next;
while(q->next->code != code)
{
q = q->next;
p = q ->next;
}
i = Listname(str, p->name);
NUMBER[i]--;
printf("%-10c%-10d%-10f.2\n", p->name, p->price, NUMBER[i]);
printf("\n");
sum += p->price;
goodnum++;
q->next = p->next;
free(p);
}
void Listpint(SqList &L)//进行商品销售
{
int x = 1;
char code[20];
printf("\t\t\t\t\t编号 名称 价格 数量\n");
while(x)
{
printf("编号:");
scanf("%s", code);
ListDelete2(L, code);
printf("\ncontinue or not (1 or 0):");
scanf("%d", &x);
}
printf("the sum price of all goods is %f \n", sum);
printf("the number of the goods is %d \n", goodnum);
}
void Listrecord(SqList &L)//退出并把数据写入文件//
{
FILE *fp;
Lnode *pnew;
fp = fopen("data.txt","w");
if(fp == NULL)
{
printf("can not open the file!\n");
exit(0);
}
for(pnew=L->next;pnew!=NULL;pnew=pnew->next)
{
if(pnew->next!=NULL)
{
fputs (pnew->name, fp);
fputs ("\n",fp);
fprintf(fp,"%f",pnew->price);
fputs ("\n",fp);
fprintf(fp,"%s",pnew->code);
fputs ("\n",fp);
}
else
{
fputs(pnew->name, fp);
fputs("\n", fp);
fprintf(fp, "%f", pnew->price);
fputs("\n", fp);
fprintf(fp,"%s", pnew->code);
fputs("\n", fp);
fclose(fp);
}
}
}
void Listallprint(SqList L)
{
FILE *fp;
Lnode *q;
int i;
q = L->next;
printf("编号 名称 价格 数量\n");
while(q->next != NULL)
{
i = Listname(str, q->name);
printf("%-10c%-10c%-10.2f%-10d\n", q->code, q->name, q->price, NUMBER[i]);
printf("------------------------------------------------------------------\n");
printf("\n");
}
printf("\n");
printf("\n");
printf("\n");
printf("\t\t\t\t商品存货信息");
printf("------------------------------------------------------");
q = L->next;
while(q->next != NULL)
{
i = Listname(str,q->name);
if(i < M)
printf("the good of %d is not enough ,please buy some\n", str[i]);
}
fp = fopen("data.text", "r");
if(fp == NULL)
{
printf("can not open the file!");
exit(0);
}
fclose(fp);
}