莫名奇妙要输入分号,但应该是不用的,该怎么办?
```c++
#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#define _CRT_SECURE_NO_WARNINGS
//图书信息
//用户信息
using namespace std;
struct bookinfo
{
char bookname[20];//书名
char ISBN[15];//书号,一般13位
char writer[20];//作者
int nownum;//现存
int storenum;//库存
};
struct Node//链表结点;
{
struct bookinfo data;
struct Node* next;
};
struct Node* list = NULL;
struct Node* creathead()//头指针
{
struct Node* headnode = (struct Node*)malloc(sizeof(struct Node));
headnode->next = NULL;
return headnode;
}
struct Node* creatnode(struct bookinfo data)
{
struct Node* newnode = (struct Node*)malloc(sizeof(struct Node));
newnode->data = data;
newnode->next = NULL;
return newnode;
}
typedef struct {
char name[20];
char id[20];
struct bookinfo userbook[5];
}user;
//插入新书,表头插入
void insertnodebyhead(struct Node* headnode, struct bookinfo data)
{
struct Node* newnode = creatnode(data);
newnode->next = headnode->next;
headnode->next = newnode;
}
//指定位置删除
void deleteNodeByData(struct Node* headnode, char* bookname)
{
struct Node* posleftnode = headnode;
struct Node* posnode = headnode->next;
while (posnode != NULL && strcmp(posnode->data.bookname, bookname))
{
posleftnode = posnode;
posnode = posleftnode->next;
}
if (posnode == NULL)
return;
else
{
posleftnode->next = posnode->next;
free(posnode);
posnode = NULL;
}
}
Node* LocateElem(struct Node* headnode, char* isbn)
{
struct Node* p;
p = headnode->next;
while (p && p->data.ISBN == isbn)
{
p = p->next;
return p;
}
}
void printlist(struct Node* headnode)//打印,看情况
{
struct Node* pmove = headnode->next;
printf("书名\t书号\t作者\t现存量\t库存量\n");
while (pmove != NULL)
{
printf("%s\t%s\t%s\t%d\t%d\t", pmove->data.bookname, pmove->data.ISBN, pmove->data.writer, pmove->data.nownum, pmove->data.storenum);
pmove = pmove->next;
}
}
void makemenu()//界面
{
printf("*****************************************\n");
printf(" 华南理工大学图书管理系统\n");
printf("\t0.退出系统\n");
printf("\t1.登记入库\n");
printf("\t2.借阅书籍\n");
printf("\t3.归还书籍\n");
printf("\t4.入库旧书\n");
printf("\t5.打印图书列表\n");
printf("*****************************************\n");
printf("请输入0 - 5 :");
}
//存操作
void saveinfotofile(const char* filename, struct Node* headnode)
{
FILE* fp = fopen(filename, "w");
struct Node* pmove = headnode->next;
while (pmove != NULL)
{
fprintf(fp, "%s\t%s\t%s\t%d\t%d\n", pmove->data.bookname, pmove->data.ISBN, pmove->data.writer, pmove->data.nownum, pmove->data.storenum);
pmove = pmove->next;
}
fclose(fp);
}
//写操作
void readinfotofile(const char* filename, struct Node* headnode)
{
FILE* fp = fopen(filename, "r");
if (fp == NULL)//第一次打开文件不存在
{
fp = fopen(filename, "w+");
}
struct bookinfo temp;
while (fscanf(fp, "%s\t%s\t%s\t%d\t%d\n", temp.bookname, temp.ISBN, temp.writer, &temp.nownum, &temp.storenum) != EOF)
{
insertnodebyhead(list, temp);
}
fclose(fp);
}
void key()
{
int userkey = 0;
struct bookinfo tempbook;//临时变量存储信息
scanf("%d", &userkey);
switch (userkey)
{
case 0:
printf("【退出】\n");
printf("退出成功\n");
system("pause");
exit(0); //退出
break;
case 1:
printf("【登记新书】\n");
printf("输入书籍信息(书名,书号ISBN,作者,现存,库存):");
scanf("%s\t%s\t%s\t%d\t%d", tempbook.bookname, tempbook.ISBN, tempbook.writer, &tempbook.nownum, &tempbook.storenum);
insertnodebyhead(list, tempbook);
saveinfotofile("bookinfo.txt", list); break;
case 2:
printf("【借阅】\n");//判断库存
printf("请输入借阅的书名\n");
scanf("%s", tempbook.bookname);
if (LocateElem(list, tempbook.bookname) == NULL)
{
printf("无相关书籍\n");
}
else {
if (LocateElem(list, tempbook.bookname)->data.nownum > 0)
{
LocateElem(list, tempbook.bookname)->data.nownum--;
printf("借阅成功\n");
}
else printf("书籍无现存,借阅失败\n");
}
break;
case 3:
printf("【归还】\n");
printf("请输入归还的书名\n");
scanf("%s", tempbook.bookname);
if (LocateElem(list, tempbook.bookname) == NULL)
{
printf("无相关书籍\n");
}
else {
LocateElem(list, tempbook.bookname)->data.nownum++;
printf("书籍归还成功\n");
}
break;
case 4:printf("【旧书入库】\n");
printf("输入书籍信息(书名,书号ISBN,作者,现存,新增库存):");
scanf("%s\t%s\t%s\t%d\t%d", tempbook.bookname, tempbook.ISBN, tempbook.writer, &tempbook.nownum, &tempbook.storenum);
if (LocateElem(list, tempbook.ISBN))
{
LocateElem(list, tempbook.ISBN)->data.nownum += tempbook.nownum;
LocateElem(list, tempbook.ISBN)->data.storenum += tempbook.storenum;
}
saveinfotofile("bookinfo.txt", list);
break;
case 5: printlist(list);
default:
printf("【ERROR】\n");
break;
}
int main()
{
list = createhead();
readinfotofile("bookinfo.txt", list);
while (1)
{
makemenu();
key();
system("pause");
system("cls");
}
system("pause");
return 0;
}
```