花隐521 2023-02-18 14:47 采纳率: 100%
浏览 33
已结题

C++问题 ,莫名其妙地显示错误,要输入分号

莫名奇妙要输入分号,但应该是不用的,该怎么办?

img


```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;

    }

```

  • 写回答

4条回答 默认 最新

  • 白驹_过隙 算法领域新星创作者 2023-02-18 14:52
    关注

    void key()函数最后少了大括号

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 2月26日
  • 已采纳回答 2月18日
  • 创建了问题 2月18日

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探