user-0 提问: 大佬帮帮忙，改下C语言代码

回复:
user: user-1
content: 替换所有 gets 为 scanf  推荐 scanf 使用格式  scanf("%d%*1024[^\r\n]%*c", &a);   排除不需要的输入和烦人的回车  ---  目前判断输入缓存问题

user: user-0
content: printf("\n\n\n\n\n\n\n"); 		printf("**************************************************************"); 		printf("\n南邮图书馆管理员功能系统\n"); 		printf("1.添加书籍信息\n"); 		printf("2.删除书籍信息\n"); 		printf("3.修改书籍信息\n"); 		printf("4.查询书籍信息\n"); 		printf("5.查询用户信息\n"); 		printf("0.退出\n"); 		printf("**************************************************************"); 		printf("\n\n\n\n\n\n\n"); 		printf("输入您需要进行的操作: "); 		scanf("%d", &cmd); 		getchar(); 		switch (cmd) 		{ 		case 1: 			addbook(); 			break; 		case 2: 			deletebook(); 			break; 		case 3: 			changebook(); 			break; 		case 4: 			searchbook(); 			break; 		case 5: 			searchuser(); 			break; 		case 0: 			end = 1; 			break; 		default: 			printf("错误的输入!\n"); 		} 		if (end == 1) 			break; 	} }   void adminregister() { 	struct adminstruct *p; 	char adminname[1000]; 	char adminscert[1000]; 	FILE *fp;   	system("cls"); 	if (admincount == 0)            //第一次添加 	{ 		adminhead = (struct adminstruct *)malloc(sizeof(struct adminstruct)); 		printf("adminname: "); 		while (gets(adminname)) 		{ 			if (strlen(adminname) < 10) 				break; 			else 				printf("too long"); 		} 		strcpy(adminhead->adminname, adminname); 		printf("adminscert: "); 		while (gets(adminscert)) 		{ 			if (strlen(adminscert) < 10) 				break; 			else 				printf("too long"); 		} 		strcpy(adminhead->scert, adminscert); 		adminend = adminhead; 		adminend->next = NULL; 	} 	else 	{ 		p = (struct adminstruct *)malloc(sizeof(struct adminstruct)); 		printf("adminname: "); 		while (gets(adminname)) 		{ 			if (strlen(adminname) < 10) 				break; 			else 				printf("too long"); 		} 		strcpy(p->adminname, adminname); 		printf("adminscert: "); 		while (gets(adminscert)) 		{ 			if (strlen(adminscert) < 10) 				break; 			else 				printf("too long"); 		} 		strcpy(p->scert, adminscert); 		adminend->next = p; 		adminend = p; 		adminend->next = NULL; 	} 	admincount++;   	fp = fopen("admin", "w"); 	p = adminhead; 	while (p != NULL) 	{ 		fwrite(p, sizeof(struct adminstruct), 1, fp); 		p = p->next; 	} 	fclose(fp);   	system("cls"); 	printf("管理员%s创建成功\n", adminend->adminname); 	printf("3秒后自动返回主界面....\n"); 	Sleep(3000); }   void borrowbook(struct userstruct *userp) { 	struct bookstruct *p; 	char bookname[100]; 	int exist = 0;   	system("cls"); 	p = bookhead; 	while (p != NULL) 	{ 		printf("bookname: %10s\tbookcount: %3d\n", p->bookname, p->count); 		p = p->next; 	} 	printf("输入您需要借阅的书籍名称: "); 	getchar(); 	gets(bookname);   	p = bookhead; 	while (p != NULL) 	{ 		if (strcmp(bookname, p->bookname) == 0) 		{ 			if (p->count == 0) 				printf("此书无余量..."); 			else 			{ 				p->count -= 1; 				userp->bookcount++; 				strcpy(userp->booklist[userp->bookcount - 1], p->bookname); 				writefile(0); 				writefile(2); 				exist = 1; 				break; 			} 		} 		p = p->next; 	}   	if (exist == 0) 		printf("不存在此书!\n"); 	else 		printf("%s借阅成功", p->bookname); 	printf("3秒后返回用户界面..."); 	Sleep(3000); }   void returnbook(struct userstruct *userp) { 	struct bookstruct *p; 	char bookname[100]; 	int count = userp->bookcount; 	int exist; 	int flag;     int i; 	system("cls"); 	p = bookhead; 	while (count--) 	{ 		printf("booklist:\n"); 		printf("%s\n", userp->booklist[count]); 	} 	printf("\n\n\n\n\n"); 	printf("**************************************************************"); 	printf("\n输入你需要归还的书籍名称: ");   	scanf("%s",&bookname[100]); 	while(bookname[100]) 	{ 		exist = 0; 		for (i = 0; i < userp->bookcount; i++) 		{ 			if (strcmp(bookname, userp->booklist[i]) == 0) 			{ 				flag = i; 				exist = 1; 				break; 			} 		} 		if (!exist) 		{ 			printf("你借阅的书籍中不存在此书籍...\n"); 			printf("请重新输入你需要归还的书籍名称: "); 		} 		else 			break; 	} 	printf("**************************************************************"); 	while (p != NULL) 	{ 		if (strcmp(p->bookname, bookname) == 0) 		{ 			p->count++; 			break; 		} 		p = p->next; 	}   	for (i = flag; i < userp->bookcount - 1; i++) 	{ 		strcpy(userp->booklist[i], userp->booklist[i + 1]); 	} 	userp->bookcount--; 	writefile(0); 	writefile(2); 	printf("\n%s归还成功...", bookname); 	printf("3秒后自动跳转回用户界面..."); 	Sleep(3000); }   void findbook(struct userstruct *userp) { 	int count = userp->bookcount; 	int n;   	system("cls"); 	printf("\n\n\n\n\n"); 	printf("**************************************************************"); 	printf("\nbooklist:\n"); 	while (count--) 	{ 		printf("%s\n", userp->booklist[count]); 	} 	printf("**************************************************************"); 	printf("\n输入0返回用户界面: "); 	while (1) 	{ 		scanf("%d", &n); 		if (n == 0) 			break; 		else 			printf("无效的输入，请重新输入: "); 	} }   void addbook() {    int isexist = 0; 	struct bookstruct *p; 	char bookname[100]; 	FILE *fp;   	system("cls"); 	if (bookcount == 0) 	{ 		printf("输入新增书籍的书名: "); 		while (gets(bookname)) 		{ 			if (strlen(bookname) > 10) 				printf("too long\n"); 			else 				break; 		} 		strcpy(bookhead->bookname, bookname); 		printf("id: "); 		scanf("%d", &bookhead->id); 		printf("author: "); 		scanf("%s", bookhead->author); 		printf("bookyear: "); 		scanf("%d", &bookhead->year); 		printf("bookmonth: "); 		scanf("%d", &bookhead->month); 		printf("bookday: "); 		scanf("%d", &bookhead->day); 		printf("bookcount: "); 		scanf("%d", &bookhead->count);   		bookend = bookhead; 		bookend->next = NULL; 	} 	else 	{ 		printf("输入新增书籍的书名: "); 		while (gets(bookname)) 		{ 			if (strlen(bookname) > 10) 				printf("too long\n"); 			else 				break; 		} 		 		p = bookhead; 		while (p != NULL) 		{ 			if (strcmp(bookname, p->bookname) == 0) 			{ 				isexist = 1; 				break; 			} 			p = p->next; 		} 		if (isexist == 1) 		{ 			int count;

user: user-0
content: void startsys() { 	int cmd; 	int end = 0;   	while (1) 	{ 		system("cls"); 		printf("\n\n\n\n\n\n\n"); 		printf("**************************************************************"); 		printf("\南邮图书馆管理系统\n"); 		printf("1.用户登陆\n"); 		printf("2.管理员登陆\n"); 		printf("3.用户注册\n"); 		printf("4.管理员注册\n"); 		printf("0.退出\n"); 		printf("**************************************************************"); 		printf("\n\n\n\n\n\n\n"); 		printf("输入你需要进行的操作: "); 		scanf("%d", &cmd); 		 		switch (cmd) 		{ 		case 1: 			userlogin(); 			break; 		case 2: 			adminlogin(); 			break; 		case 3: 			userregister(); 			break; 		case 4: 			adminregister(); 			break; 		case 0: 			end = 1; 			break; 		default: 			printf("错误输入!\n"); 		} 		if (end == 1) 			break; 	} }   void userlogin() { 	struct userstruct *p; 	char username[10]; 	char scert[10]; 	int exist = 0; 	   	p = head; 	system("cls"); 	printf("\n\n\n\n\n\n\n"); 	printf("**************************************************************"); 	printf("\n输入您的用户信息: \n"); 	printf("username: "); 	scanf("%s",&username[100]); 	printf("userscert: "); 	scanf("%s",&scert[100]); 	printf("**************************************************************"); 	printf("\n\n\n\n\n\n\n");   	while (p != NULL) 	{ 		if (strcmp(p->username, username) == 0) 		{ 			exist = 1; 			while(strcmp(p->scert, scert) != 0) 			{ 				printf("密码错误!请重新输入\n"); 				printf("userscert: "); 				gets(scert); 			} 			printf("用户%s登陆成功!3秒后自动跳转至用户界面...", p->username); 			Sleep(3000); 			userfunction(p); 		} 		p = p->next; 	} 	if (!exist) 	{ 		printf("不存在此用户名,请先前往注册...\n"); 		printf("3秒后自动跳转至主界面..."); 		Sleep(3000); 	} }   void userfunction(struct userstruct *p) { 	int cmd; 	int end = 0;   	while (1) 	{ 		system("cls"); 		printf("\n\n\n\n\n\n\n"); 		printf("**************************************************************"); 		printf("\n南邮图书馆用户功能系统\n"); 		printf("1.借阅书籍\n"); 		printf("2.归还书籍\n"); 		printf("3.已借阅书籍信息\n"); 		printf("0.退出\n"); 		printf("**************************************************************"); 		printf("\n\n\n\n\n\n\n"); 		printf("输入您需要进行的操作: "); 		scanf("%d", &cmd); 		switch (cmd) 		{ 		case 1: 			borrowbook(p); 			break; 		case 2: 			returnbook(p); 			break; 		case 3: 			findbook(p); 			break; 		case 0: 			end = 1; 			break; 		default: 			printf("错误的输入!\n"); 		} 		if (end == 1) 			break; 	} }   void userregister() { 	struct userstruct *p; 	char username[100]; 	char scert[100]; 	FILE *fp;   	system("cls"); 	if (usercount == 0)            //第一次添加 	{ 		printf("username: "); 		while (gets(username)) 		{ 			if (strlen(username) < 10 && !isexist(username, 0)) 				break; 			else if (isexist(username, 0)) 			{ 				printf("该用户名已经存在!\n"); 				printf("username: "); 			} 			else 			{ 				printf("too long\n"); 				printf("username: "); 			} 		} 		strcpy(head->username, username); 		printf("userscert: "); 		while (gets(scert)) 		{ 			if (strlen(scert) < 10) 				break; 			else 				printf("too long"); 		} 		strcpy(head->scert, scert); 		head->bookcount = 0; 		end = head; 		end->next = NULL;   	} 	else 	{ 		p = (struct userstruct *)malloc(sizeof(struct userstruct)); 		printf("username: "); 		while (gets(username)) 		{ 			if (strlen(username) < 10 && !isexist(username, 0)) 				break; 			else if (isexist(username, 0)) 			{ 				printf("该用户名已经存在!\n"); 				printf("username: "); 			} 			else 			{ 				printf("too long\n"); 				printf("username: "); 			} 		} 		strcpy(p->username, username); 		printf("userscert: "); 		while (gets(scert)) 		{ 			if (strlen(scert) < 10) 				break; 			else 				printf("too long"); 		} 		strcpy(p->scert, scert); 		p->bookcount = 0; 		end->next = p; 		end = p; 		end->next = NULL; 	} 	usercount++;     	fp = fopen("user", "w"); 	p = head; 	while (p != NULL) 	{ 		fwrite(p, sizeof(struct userstruct), 1, fp); 		p = p->next; 	} 	fclose(fp);   	system("cls"); 	printf("用户%s创建成功\n", end->username); 	printf("3秒后自动返回主界面....\n"); 	Sleep(3000); }   int isexist(char *name,int flag) { 	if (flag == 0) 	{ 		struct userstruct *p; 		p = head; 		while (p != NULL && usercount != 0) 		{ 			if (strcmp(name, p->username) == 0) 				return 1; 			p = p->next; 		} 	} 	else if (flag == 1) 	{ 		struct adminstruct *p; 		p = adminhead; 		while (p != NULL) 		{ 			if (strcmp(name, p->adminname) == 0) 				return 1; 			p = p->next; 		} 	} 	else if (flag == 2) 	{ 		struct bookstruct *p; 		p = bookhead; 		while (p != NULL) 		{ 			if (strcmp(name, p->bookname) == 0) 				return 1; 			p = p->next; 		} 	} 	return 0; }   void adminlogin() { 	struct adminstruct *p; 	char adminname[100]; 	char adminscert[100];   	p = adminhead; 	system("cls"); 	printf("\n\n\n\n\n\n\n"); 	printf("**************************************************************"); 	printf("\n输入您的管理员信息: \n"); 	printf("adminname: "); 	gets(adminname); 	printf("adminscert: "); 	gets(adminscert); 	printf("**************************************************************"); 	printf("\n\n\n\n\n\n\n");   	while (p != NULL) 	{ 		if (strcmp(p->adminname, adminname) == 0) 		{ 			while (strcmp(p->scert, adminscert) != 0) 			{ 				printf("密码错误!请重新输入\n"); 				printf("adminscert: "); 				gets(adminscert); 			} 			printf("管理员%s登陆成功!3秒后自动跳转至用户界面...", p->adminname); 			Sleep(3000); 			 		} 		p = p->next; 	} }   void adminfunction() { 	int cmd; 	int end = 0;   	while (1) 	{ 		system("cls");

user: user-0
content: #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<windows.h> #include<conio.h> struct userstruct        /*用户*/ { 	int bookcount; 	char username[100]; 	char scert[100]; 	char booklist[10][20]; 	struct userstruct *next; }; struct adminstruct       /*管理员*/ { 	char adminname[10]; 	char scert[10]; 	struct adminstruct *next; }; struct bookstruct { 	int id; 	char bookname[10]; 	char author[10]; 	int year; 	int month; 	int day; 	int count; 	struct bookstruct *next; }; struct userstruct *head = NULL, *end = NULL; struct adminstruct *adminhead = NULL, *adminend = NULL; struct bookstruct *bookhead = NULL, *bookend = NULL; int usercount, admincount, bookcount;   void startsys(); void readuserfile(); void readadminfile(); void readbookfile(); void userlogin(); void userfunction(struct userstruct *p); void userregister(); void adminlogin(); void adminregister(); void adminfunction(); void borrowbook(struct userstruct *userp); void findbook(struct userstruct *userp); void returnbook(struct userstruct *userp); void addbook(); void deletebook(); void searchbook(); void changebook(); void searchuser(); void writefile(int flag); void changuserbook(char *userbookname,char *bookname); void deleteuserbook(char *bookname); int isexist(char *name,int flag);  int main() { 	FILE *fp;   	head = (struct userstruct *)malloc(sizeof(struct userstruct)); 	adminhead = (struct adminstruct *)malloc(sizeof(struct adminstruct)); 	bookhead = (struct bookstruct *)malloc(sizeof(struct bookstruct));   	fp = fopen("user", "a+"); 	usercount = fread(head, sizeof(struct userstruct), 1, fp); 	fclose(fp); 	end = head; 	readuserfile();   	fp = fopen("admin", "a+"); 	admincount = fread(adminhead, sizeof(struct adminstruct), 1, fp); 	fclose(fp); 	adminend = adminhead; 	readadminfile();   	fp = fopen("book", "a+"); 	bookcount = fread(bookhead, sizeof(struct bookstruct), 1, fp); 	fclose(fp); 	bookend = bookhead; 	readbookfile();   	startsys(); 	return 0; }

user: user-2
content: 建议直接贴出代码