如图所示,它要我在int ReCheck(char str[])后加上分号“;”,但是加完后,{}里的东西又出现了错误,这应该怎么改啊?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <Windows.h>
#include <conio.h>
char ch, c, h;//选择
struct BOOK
{
char bianhao[11];//图书编号
char bookname[50];//书名
char writer[50];//作者
char leibie[20];//图书类型
char chubanfang[50];//出版方
char data[11];//出版日期
float price;//价格
int num;//数量
struct BOOK* next;
};
struct BOOK* head;
struct BOOK* p;
void gotoxy(int x, int y);//光标移动
void JM();//界面
void DelJM();//删除功能界面
void Next();//输入y继续,输入其他键退出
void output(struct BOOK* head);//输出链表
void CL();//创建保存链表
void Save();//保存提示框
void Del();//删除提示框
void Succeed();//成功
void FileSave();//文件保存
void PXJM();//排序界面
void FileRead(struct BOOK* HEAD);//文件读取
void DelWriter(struct BOOK* HEAD);//删除作者
void DelBook(struct BOOK* HEAD);//删除图书(编号或书名)
void PX_b(struct BOOK* HEAD);//编号排序
void PX_p(struct BOOK* HEAD);//价格排序
void Check();//图书查询
void Change();//图书信息修改
int FRN();//判断是否文件为空
void menu();//主菜单
void menu5();//选项5复菜单
void menu3();//选项3复菜单
int ReCheck(char str[]);//判断输入编号是否重复
//主函数:
int main(void)
{
menu();
return 0;
}
//自定义函数:
void gotoxy(int x, int y)
{
COORD pos = { x, y };
HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}
void JM()
{
system("cls");
printf("*请最大化使用*");
gotoxy(80, 11); printf("*********图书管理系统*********");
gotoxy(80, 13); printf(" | 1.图书信息录入 |");
gotoxy(80, 15); printf(" | 2.图书信息查询 |");
gotoxy(80, 17); printf(" | 3.图书信息删除 |");
gotoxy(80, 19); printf(" | 4.图书信息修改 |");
gotoxy(80, 21); printf(" | 5.图书信息总览 |");
gotoxy(80, 23); printf(" | 6.退出程序 |");
gotoxy(86, 25); printf("输入序号,选择功能");
}
void Next()
{
printf("输入y继续,输入其他键退出");
}
void Continue()
{
system("cls");
gotoxy(75, 20); printf("----------------------------------------\n");
gotoxy(75, 22); printf("| |\n");
gotoxy(75, 24); printf("| Continue to enter information? |\n");
gotoxy(75, 26); printf("| y / n |\n");
gotoxy(75, 28); printf("| |\n");
gotoxy(75, 30); printf("----------------------------------------\n");
gotoxy(75, 32); printf(" 输入y继续录入信息,输入n结束录入!");
}
void Save()
{
system("cls");
gotoxy(80, 20); printf("---------------------------\n");
gotoxy(80, 22); printf("| |\n");
gotoxy(80, 24); printf("| Are you save it ? |\n");
gotoxy(80, 26); printf("| y / n |\n");
gotoxy(80, 28); printf("| |\n");
gotoxy(80, 30); printf("---------------------------\n");
gotoxy(80, 32); printf(" 输入y保存!输入n取消!");
}
void Del()
{
system("cls");
gotoxy(80, 20); printf("---------------------------\n");
gotoxy(80, 22); printf("| |\n");
gotoxy(80, 24); printf("| Are you delete it ? |\n");
gotoxy(80, 26); printf("| y / n |\n");
gotoxy(80, 28); printf("| |\n");
gotoxy(80, 30); printf("---------------------------\n");
gotoxy(80, 32); printf(" 输入y保存!输入n取消!");
}
void DelJM()
{
system("cls");
gotoxy(80, 11); printf("*********图书管理系统*********");
gotoxy(80, 13); printf(" | 1.删除某作者图书 |");
gotoxy(80, 15); printf(" | 2.编号或书名删除 |");
gotoxy(80, 17); printf(" | 3.返回系统主界面 |");
gotoxy(86, 25); printf(" 输入序号,选择功能");
//c = getch();
}
void PXJM()
{
system("cls");
gotoxy(80, 11); printf("*********图书管理系统*********");
gotoxy(80, 13); printf(" | 1.按图书编号排序 |");
gotoxy(80, 15); printf(" | 2.按图书价格排序 |");
gotoxy(80, 17); printf(" | 3.返回系统主界面 |");
gotoxy(86, 19); printf(" 输入序号,选择功能");
}
void CL()//创建链表
{
head->next = NULL;
p = (struct BOOK*)malloc(sizeof(struct BOOK));
p->next = NULL;
loop:
{
struct BOOK* s = (struct BOOK*)malloc(sizeof(struct BOOK));
gotoxy(80, 11); printf("请输入图书编号(小于10位):");
loop1:scanf("%s", s->bianhao);
if (ReCheck(s->bianhao) == -1)
{
system("cls");
gotoxy(80, 11); printf("输入的编号重复!请重新输入编号:");
goto loop1;
}
gotoxy(80, 13); printf("请输入书名(小于25字):");
scanf("%s", s->bookname);
gotoxy(80, 15); printf("请输入作者姓名(小于25字):");
scanf("%s", s->writer);
gotoxy(80, 17); printf("请输入图书类别(小于10字):");
scanf("%s", s->leibie);
gotoxy(80, 19); printf("请输入图书出版方(小于25字):");
scanf("%s", s->chubanfang);
gotoxy(80, 21); printf("请输入图书出版日期(如2018.03.03):");
scanf("%s", s->data);
gotoxy(80, 23); printf("请输入图书价格:");
scanf("%f", &s->price);
gotoxy(80, 25); printf("请输入图书数量:");
scanf("%d", &s->num);
if (head->next == NULL)
{
head->next = s;
s->next = NULL;
}
else
{
p->next = s;
s->next = NULL;
}
p = s;
//文件存储
Save();
char a;
loop2:
a = getch();
if (a == 'y' || a == 'Y')
{
FileSave();
Succeed();
Sleep(1000);
}
else if (a == 'n' || a == 'N')
{
system("cls");
gotoxy(90, 25); printf("修改未保存!");
Sleep(1000);
system("cls");
}
else
{
goto loop2;
}
gotoxy(80, 25); Continue();
ch = getch();
if (ch == 'y' || ch == 'Y')
{
system("cls");
goto loop;
}
}
}
void output(struct BOOK* s)
{
int t = 0;
system("cls");
struct BOOK* p = (struct BOOK*)malloc(sizeof(struct BOOK));
p = s;
gotoxy(33, 6); printf("----------------------------------------------------------------------------------------------------------------------------------\n");
gotoxy(40, 7); printf("图书编号 书名 作者 图书类别 出版方 出版日期 图书价格 图书数量\n");
gotoxy(33, 8); printf("----------------------------------------------------------------------------------------------------------------------------------\n");
while (p->next != NULL)
{
gotoxy(40, 9 + t); printf("%s", p->next->bianhao);
gotoxy(55, 9 + t); printf("%s", p->next->bookname);
gotoxy(69, 9 + t); printf("%s", p->next->writer);
gotoxy(82, 9 + t); printf("%s", p->next->leibie);
gotoxy(99, 9 + t); printf("%s", p->next->chubanfang);
gotoxy(114, 9 + t); printf("%s", p->next->data);
gotoxy(131, 9 + t); printf("%g", p->next->price);
gotoxy(150, 9 + t); printf("%d\n", p->next->num);
t = t + 2;
p = p->next;
}
}
void FileSave()
{
char a;
a = getch();
system("cls");
if (a == 'y' || a == 'Y')
{
FILE* fp = fopen("bookinformation.txt", "a");
if (fp == NULL)
{
printf("打开文件失败!\n");
return 0;
}
fprintf(fp, "%s %s %s %s %s %s %g %d\n", p->bianhao, p->bookname, p->writer, p->leibie, p->chubanfang, p->data, p->price, p->num);
fclose(fp);
}
}
void FileRead(struct BOOK* HEAD)
{
FILE* fp = fopen("bookinformation.txt", "rt");
if (fp == NULL)
{
printf("文件打开失败!\n");
return 0;
}
struct BOOK* p = (struct BOOK*)malloc(sizeof(struct BOOK));
p->next = NULL;
while (!feof(fp))//判断是否读到文件尾
{
struct BOOK* s = (struct BOOK*)malloc(sizeof(struct BOOK));
fscanf(fp, "%s %s %s %s %s %s %f %d\n", s->bianhao, s->bookname, s->writer, s->leibie, s->chubanfang, s->data, &s->price, &s->num);
if (HEAD->next == NULL)
{
HEAD->next = s;
s->next = NULL;
}
else
{
p->next = s;
s->next = NULL;
}
p = s;
}
}
void DelWriter(struct BOOK* HEAD)
{
int t = 0;
int a = 0;//删除后链表长度计数器
char ch[50];
struct BOOK* q1 = (struct BOOK*)malloc(sizeof(struct BOOK));
q1->next = NULL;
struct BOOK* q2 = (struct BOOK*)malloc(sizeof(struct BOOK));
q2->next = NULL;
q1 = HEAD;
gotoxy(75, 20); printf("请输入要删除的图书的作者:");
scanf("%s", ch);
while (q1->next != NULL)
{
a++;
q2 = q1->next;
if (q2->next != NULL && (strcmp(ch, q2->writer) == 0))
{
t++;
a--;
q1->next = q2->next;
q2 = q2->next;
continue;
}
else if (q2->next == NULL && (strcmp(ch, q2->writer) == 0))
{
t++;
a--;
q1->next = NULL;
break;
}
q1 = q1->next;
}
if (t != 0)
{
loop:
Del();
char c;
c = getch();
if (c == 'y' || c == 'Y')
{
q1 = HEAD->next;
FILE* fp = fopen("bookinformation.txt", "wt");
if (fp == NULL)
{
printf("打开文件失败!\n");
return 0;
}
for (int i = 0; i < a; i++)
{
fprintf(fp, "%s %s %s %s %s %s %g %d\n", q1->bianhao, q1->bookname, q1->writer, q1->leibie, q1->chubanfang, q1->data, q1->price, q1->num);
q1 = q1->next;
}
fclose(fp);
Succeed();
Sleep(1000);
system("cls");
}
else if (c == 'n' || c == 'N')
{
system("cls");
gotoxy(83, 22); printf("修改未保存!");
gotoxy(83, 25); printf("按任意键返回删除菜单!");
getch();
menu3();
}
else
{
goto loop;
}
}
else if (t == 0)
{
gotoxy(80, 22); printf("没有找到此作者!!!");
Sleep(1000);
}
}
void DelBook(struct BOOK* HEAD)
{
int t = 0;
int a = 0;//删除后链表长度计数器
char ch[50];
struct BOOK* q1 = (struct BOOK*)malloc(sizeof(struct BOOK));
q1->next = NULL;
struct BOOK* q2 = (struct BOOK*)malloc(sizeof(struct BOOK));
q2->next = NULL;
q1 = HEAD;
gotoxy(75, 20); printf("请输入要删除的图书的编号或书名:");
scanf("%s", ch);
while (q1->next != NULL)
{
a++;
q2 = q1->next;
if (q2->next != NULL && (strcmp(ch, q2->bianhao) == 0 || strcmp(ch, q2->bookname) == 0))
{
t++;
a--;
q1->next = q2->next;
q2 = q2->next;
continue;
}
else if (q2->next == NULL && (strcmp(ch, q2->bianhao) == 0 || strcmp(ch, q2->bookname) == 0))
{
t++;
a--;
q1->next = NULL;
break;
}
q1 = q1->next;
}
if (t != 0)
{
loop:
Del();
char c;
c = getch();
if (c == 'y' || c == 'Y')
{
q1 = HEAD->next;
FILE* fp = fopen("bookinformation.txt", "wt");
if (fp == NULL)
{
printf("打开文件失败!\n");
return 0;
}
for (int i = 0; i < a; i++)
{
fprintf(fp, "%s %s %s %s %s %s %g %d\n", q1->bianhao, q1->bookname, q1->writer, q1->leibie, q1->chubanfang, q1->data, q1->price, q1->num);
q1 = q1->next;
}
fclose(fp);
Succeed();
Sleep(1000);
system("cls");
}
else if (c == 'n' || c == 'N')
{
system("cls");
gotoxy(83, 22); printf("修改未保存!");
gotoxy(83, 25); printf("按任意键返回删除菜单!");
getch();
menu3();
}
else
{
goto loop;
}
}
else
{
gotoxy(80, 22); printf("这本书还没有入库呢!!!");
}
}
void PX_b(struct BOOK* HEAD)
{
struct BOOK* q = (struct BOOK*)malloc(sizeof(struct BOOK));
q = HEAD;
int a = 0;//链表长度计数器
while (q->next != NULL)
{
a++;
q = q->next;
}
struct BOOK* q1 = (struct BOOK*)malloc(sizeof(struct BOOK));
q1->next = NULL;
struct BOOK* q2 = (struct BOOK*)malloc(sizeof(struct BOOK));
q2->next = NULL;
if (HEAD->next->next != NULL)
{
for (int i = 0; i < a - 1; i++)
{
q = HEAD;
q1 = q->next;
q2 = q1->next;
while (q2->next != NULL)
{
if (strcmp(q1->bianhao, q2->bianhao) > 0)
{
q->next = q1->next;
q1->next = q2->next;
q2->next = q1;
q2 = q1->next;
q = q->next;
continue;
}
q = q->next;
q1 = q1->next;
q2 = q2->next;
}
if (strcmp(q1->bianhao, q2->bianhao) > 0)
{
q->next = q2;
q2->next = q1;
q1->next = NULL;
}
}
}
q1 = HEAD->next;
FILE* fp = fopen("bookinformation.txt", "wt");
if (fp == NULL)
{
printf("打开文件失败!\n");
return 0;
}
for (int i = 0; i < a; i++)
{
fprintf(fp, "%s %s %s %s %s %s %g %d\n", q1->bianhao, q1->bookname, q1->writer, q1->leibie, q1->chubanfang, q1->data, q1->price, q1->num);
q1 = q1->next;
}
fclose(fp);
}
void PX_p(struct BOOK* HEAD)
{
struct BOOK* q = (struct BOOK*)malloc(sizeof(struct BOOK));
q = HEAD;
int a = 0;//链表长度计数器
while (q->next != NULL)
{
a++;
q = q->next;
}
struct BOOK* q1 = (struct BOOK*)malloc(sizeof(struct BOOK));
q1->next = NULL;
struct BOOK* q2 = (struct BOOK*)malloc(sizeof(struct BOOK));
q2->next = NULL;
if (HEAD->next->next != NULL)
{
for (int i = 0; i < a - 1; i++)
{
q = HEAD;
q1 = q->next;
q2 = q1->next;
while (q2->next != NULL)
{
if (q1->price > q2->price)
{
q->next = q1->next;
q1->next = q2->next;
q2->next = q1;
q2 = q1->next;
q = q->next;
continue;
}
q = q->next;
q1 = q1->next;
q2 = q2->next;
}
if (q1->price > q2->price)
{
q->next = q2;
q2->next = q1;
q1->next = NULL;
}
}
}
q1 = HEAD->next;
FILE* fp = fopen("bookinformation.txt", "wt");
if (fp == NULL)
{
printf("打开文件失败!\n");
return 0;
}
for (int i = 0; i < a; i++)
{
fprintf(fp, "%s %s %s %s %s %s %g %d\n", q1->bianhao, q1->bookname, q1->writer, q1->leibie, q1->chubanfang, q1->data, q1->price, q1->num);
q1 = q1->next;
}
fclose(fp);
}
void Change()
{
int t = 0;
system("cls");
FileRead(head);
struct BOOK* q = (struct BOOK*)malloc(sizeof(struct BOOK));
q = head;
char ch[50];
gotoxy(80, 15); printf("请输入需要查询图书的编号或书名:");
scanf("%s", ch);
while (q->next != NULL)
{
if (strcmp(ch, q->next->bianhao) == 0 || strcmp(ch, q->next->bookname) == 0)
{
t++;
struct BOOK* q1 = (struct BOOK*)malloc(sizeof(struct BOOK));
q1 = q->next;
system("cls");
struct BOOK* s = (struct BOOK*)malloc(sizeof(struct BOOK));
gotoxy(80, 11); printf("请重新输入图书编号(小于10位):");
scanf("%s", s->bianhao);
gotoxy(80, 13); printf("请重新输入书名(小于25字):");
scanf("%s", s->bookname);
gotoxy(80, 15); printf("请重新输入作者姓名(小于25字):");
scanf("%s", s->writer);
gotoxy(80, 17); printf("请重新输入图书类别(小于10字):");
scanf("%s", s->leibie);
gotoxy(80, 19); printf("请重新输入图书出版方(小于25字):");
scanf("%s", s->chubanfang);
gotoxy(80, 21); printf("请重新输入图书出版日期(如2018.03.03):");
scanf("%s", s->data);
gotoxy(80, 23); printf("请重新输入图书价格:");
scanf("%f", &s->price);
gotoxy(80, 25); printf("请重新输入图书数量:");
scanf("%d", &s->num);
char a;
Save();
loop:a = getch();
if (a == 'y' || a == 'Y')
{
Succeed();
Sleep(1000);
system("cls");
q->next = s;
s->next = q1->next;
}
else if (a == 'n' || a == 'N')
{
system("cls");
gotoxy(90, 25); printf("修改未保存!");
Sleep(1000);
system("cls");
}
else
{
gotoxy(80, 34); printf("请重新输入y或n!");
goto loop;
}
}
q = q->next;
}
if (t != 0)
{
q = head;
int a = 0;//链表长度计数器
while (q->next != NULL)
{
a++;
q = q->next;
}
q = head->next;
FILE* fp = fopen("bookinformation.txt", "wt");
if (fp == NULL)
{
printf("打开文件失败!\n");
return 0;
}
for (int i = 0; i < a; i++)
{
fprintf(fp, "%s %s %s %s %s %s %g %d\n", q->bianhao, q->bookname, q->writer, q->leibie, q->chubanfang, q->data, q->price, q->num);
q = q->next;
}
fclose(fp);
}
else
{
gotoxy(80, 22); printf("这本书还没有入库呢!!!");
}
}
void Check()
{
system("cls");
FileRead(head);
struct BOOK* q = (struct BOOK*)malloc(sizeof(struct BOOK));
q = head;
char ch[50];
gotoxy(80, 15); printf("请输入需要查询图书的编号或书名或作者:");
gotoxy(80, 17); scanf("%s", ch);
system("cls");
int t = 0;
while (q->next != NULL)
{
if (strcmp(ch, q->next->bianhao) == 0 || strcmp(ch, q->next->bookname) == 0 || strcmp(ch, q->next->writer) == 0)
{
gotoxy(33, 6); printf("----------------------------------------------------------------------------------------------------------------------------------\n");
gotoxy(40, 7); printf("图书编号 书名 作者 图书类别 出版方 出版日期 图书价格 图书数量\n");
gotoxy(33, 8); printf("----------------------------------------------------------------------------------------------------------------------------------\n");
gotoxy(40, 9 + t); printf("%s", q->next->bianhao);
gotoxy(55, 9 + t); printf("%s", q->next->bookname);
gotoxy(69, 9 + t); printf("%s", q->next->writer);
gotoxy(82, 9 + t); printf("%s", q->next->leibie);
gotoxy(99, 9 + t); printf("%s", q->next->chubanfang);
gotoxy(114, 9 + t); printf("%s", q->next->data);
gotoxy(131, 9 + t); printf("%g", q->next->price);
gotoxy(150, 9 + t); printf("%d\n", q->next->num);
t += 2;
}
q = q->next;
}
if (t == 0)
{
system("cls");
gotoxy(80, 21); printf("这本书还没有添加入库!!!");
}
}
void Succeed()
{
system("cls");
gotoxy(80, 20); printf("---------------------------\n");
gotoxy(80, 22); printf("| 成 功 ! |\n");
gotoxy(80, 24); printf("---------------------------\n");
}
int FRN()
{
FILE* fp;
if (fp = fopen("bookinformation.txt", "rt") == NULL)
{
return -1;
}
else
{
return 0;
}
}
void menu()
{
head = (struct BOOK*)malloc(sizeof(struct BOOK));
head->next = NULL;
system("cls");
char str;
JM();
str = getch();
switch (str)
{
case '1':
system("cls");
CL();
system("cls");
gotoxy(80, 25); printf("按任意键返回主界面!");
getch();
menu();
break;
case '2':
if (FRN() == 0)
{
Check();
}
else
{
system("cls");
gotoxy(80, 23); printf("还没添加一本图书信息呢,先去添加一本吧!");
}
gotoxy(80, 25); printf("按任意键返回主界面!");
getch();
menu();
break;
case '3':
menu3();
break;
case '4':
if (FRN() == 0)
{
Change();
}
else
{
system("cls");
gotoxy(80, 23); printf("还没添加一本图书信息呢,先去添加一本吧!");
}
gotoxy(80, 25); printf("按任意键返回主界面!");
getch();
menu();
break;
case '5':
menu5();
break;
case '6':system("cls"); exit(0); break;
default: menu();
}
}
void menu5()
{
system("cls");
if (FRN() == 0)
{
PXJM();
char c;
c = getch();
switch (c)
{
case '1':
FileRead(head);
PX_b(head);
output(head);
gotoxy(80, 25); printf("按任意键返回浏览界面!");
getch();
menu5();
break;
case '2':
FileRead(head);
PX_p(head);
output(head);
gotoxy(80, 25); printf("按任意键返回浏览界面!");
getch();
menu5();
break;
case '3':
menu();
break;
default:menu5();
}
}
else
{
system("cls");
gotoxy(80, 23); printf("还没添加一本图书信息呢,先去添加一本吧!");
gotoxy(80, 25); printf("按任意键返回主界面!");
getch();
menu();
}
void menu3();
{
system("cls");
if (FRN() == 0)
{
DelJM();
char c;
c = getch();
switch (c)
{
case '1':
system("cls");
FileRead(head);
DelWriter(head);
system("cls");
gotoxy(80, 23); printf("按任意键返回删除菜单!");
getch();
menu3();
break;
case '2':
system("cls");
FileRead(head);
DelBook(head);
gotoxy(80, 24); printf("按任意键返回删除菜单!");
getch();
menu3();
break;
case '3':
menu();
break;
default:menu3();
}
}
else
{
system("cls");
gotoxy(80, 23); printf("还没添加一本图书信息呢,先去添加一本吧!");
gotoxy(80, 25); printf("按任意键返回主界面!");
getch();
menu();
}
}
int ReCheck(char str[]);
{
if (FRN() == 0)
{
struct BOOK* Head = (struct BOOK*)malloc(sizeof(struct BOOK));
Head->next = NULL;
FileRead(Head);
struct BOOK* q = (struct BOOK*)malloc(sizeof(struct BOOK));
q = Head;
while (q->next != NULL)
{
if (strcmp(str, q->next->bianhao) == 0)
{
return -1;
}
q = q->next;
}
return 0;
}
else
{
return 0;
}
}
这个函数最后少了一个大括号“}”
void menu5()
多了两个分号
void menu3();
int ReCheck(char str[]);
int ReCheck(char str[]);
这个后面多了一个分号。
我怀疑这个前面的那个函数少了一个后花括号,因为你写着写着缩进都不对了。
如果在声明函数int ReCheck(char str[])后加上分号,则会使编译器认为该函数声明已经结束
偶遇到类似问题都是用
“每次用/.../注释掉不同部分再重新编译,直到定位到具体语法出错的位置。”
的方法解决的。