这是报错图片:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
typedef struct {
char name[20];
char leibie[20];
int number;
int price;
int member;
float time;
int zhuohao;
}restaurant;
typedef struct listnode {
restaurant data;//数据域
struct listnode* next;//指针域
}listnode, * linklist;
linklist l = NULL;
FILE* fp,*d;
char c[1000];
char m[20] = "销售额";
char file[20] = "membership";
char g[20] = "sk";
char filename[20] = "das";
void createlist() {
l = (listnode*)malloc(sizeof(listnode));
l->next = NULL;
}
void xiaoshou() {
createlist();
listnode* p, * q;
q = l;
d = fopen(m, "a+");
while (true) {
p = (listnode*)malloc(sizeof(listnode));
if (fscanf(d, "%d\t%s\t%s\t%d", &p->data.number, &p->data.name, &p->data.leibie, &p->data.price) == EOF) {
free(p);
system("pause");
break;
}
p->next = NULL;
q->next = p;
q = q->next;
}
fclose(d);
}
void diancai() {
cout << endl << endl;
cout << "\t\t\t请添加你选择的菜品信息\n";
int x = 1;
linklist p, q;
while (1) {
int s;
cout << "\t\t\t请输入菜号:";
cin >> s;
linklist g;
g = l->next;
if (g == NULL) {
cout << "\t\t\t没有菜品";
system("pause");
return;
}
cout << "\t\t\t菜号\t菜名\t\t类别\t价格\n";
while (g != NULL) {
if (g->data.number==s) {
printf("\t\t\t%d\t%s\t%s\t%d\n", g->data.number, g->data.name, g->data.leibie, g->data.price);
}
g = g->next;
}
p->data.number = g->data.number;
strcpy(p->data.name, g->data.name);
strcpy(p->data.leibie, g->data.leibie);
p->data.price = g->data.price;
if (l->next == NULL) {
p->next = NULL;
l->next = p;
}
else {
q = l->next;
while (q != NULL)
{
p->next = NULL;
q->next = p;
q = q->next;
}
}
cout << "\t\t\t继续添加输入1,结束输入0:";
cin >> x;
}
}
void xiaoshufile() {
linklist q = l->next;
d = fopen(m, "a+");
if ((d = fopen(m, "w")) == NULL) {
cout << "\t\t\t打开文件失败,";
system("pause");
return;
}
else {
while (q != NULL) {
fprintf(d, "%d\t%s\t%s\t%d\n", q->data.number, q->data.name, q->data.leibie , q->data.price);
q = q->next;
}
}
fclose(d);
system("pause");
}
void openfile() {
createlist();
listnode* g, * h;
h = l;
fp = fopen(filename, "a+");
while (true) {
g = (listnode*)malloc(sizeof(listnode));
if (fscanf(fp, "%d\t%s\t%s\t%d", &g->data.number, &g->data.name, &g->data.leibie, &g->data.price) == EOF) {
free(g);
system("pause");
break;
}
g->next = NULL;
h->next = g;
h = h->next;
}
fclose(fp);
}
void add_message() {
cout << endl << endl;
cout << "\t\t\t正在添加菜品信息\n";
int x = 1;
linklist g, h;
while (x) {
g = (listnode*)malloc(sizeof(listnode));
printf("\t\t\t正在添加菜品的信息\n");
cout << "\t\t\t请输入菜号:";
cin >> g->data.number;
g = l->next;
while (g != NULL) {
if (h->data.number == g->data.number) {
cout << "\t\t\t菜号重复,重新输入\n";
cin >> g->data.number;
h = l->next;
continue;
}
else h = h->next;
}
cout << "\t\t\t请输入菜名:";
cin >> g->data.name;
cout << "\t\t\t请输入类别:";
cin >> g->data.leibie;
cout << "\t\t\t请输入价格:";
cin >> g->data.price;
cout << "\n";
if (l->next == NULL) {
g->next = NULL;
l->next = g;
}
else {
h = l->next;
while (h != NULL)
{
if (h->next != NULL)
{
if (g->data.number > h->data.number && g->data.number < h->next->data.number) {
g->next = h->next;
h->next = g;
break;
}
}
else {
g->next = NULL;
h->next = g;
break;
}
h = h->next;
}
}
cout << "\t\t\t继续添加输入1,结束输入0:";
cin >> x;
}
}
void print_message() {
cout << "\n\n\t\t\t显示菜品信息\n";
linklist g;
g = l->next;
cout << "\t\t\t菜号\t菜名\t\t类别\t价格\n";
if (g == NULL) {
cout << "\t\t\t没有数据!";
system("pause");
return;
}
while (g != NULL) {
printf("\t\t\t%d\t%s\t%s\t%d\n", g->data.number, g->data.name, g->data.leibie, g->data.price);
g = g->next;
}
system("pause");
}
void save_file() {
linklist h = l->next;
if ((fp = fopen(filename, "w")) == NULL) {
cout << "\t\t\t打开文件失败,";
system("pause");
return;
}
else {
while (h != NULL) {
fprintf(fp, "%d\t%s\t%s\t%d\n", h->data.number, h->data.name, h->data.leibie, h->data.price);
h = h->next;
}
}
fclose(fp);
cout << "\t\t\t保存成功,";
system("pause");
}
int main() {
cout << "\n\n\t\t\t1.初始文件中信息的添加\n";
cout << "\n\n\t\t\t2.从初始文件往另一个文件里进行信息的添加\n";
int x;
while (scanf("%d", &x) != EOF) {
switch (x) {
case 1:
openfile();
add_message();
print_message();
save_file();
break;
case 2:
xiaoshou();
openfile();
diancai();
xiaoshufile();
break;
}
}
}
希望有人可以帮帮我,改一下错误。