【发布时间】:2022-01-23 11:38:47
【问题描述】:
我正在尝试编写代码构建和运行程序,但出现了此错误消息:
'MAX_BOOK_NAME' undeclared (first use in this function)
我面临的另一个问题是程序需要并实现以下内容: 您必须使用以下结构来存储有关一本书的信息:
struct book {
char *title;
char *author;
char *subject;
};
您必须使用以下结构来存储有关图书馆收藏的信息:
struct library {
struct book collection;
int num_books;
struct library *next;
};
您需要编写的唯一函数是复制函数,它将一本书的内容复制到另一本书。这是该函数的原型:
void copybook(struct book* dest, struct book* source);
虽然不会给出其余的函数原型,但希望您遵循良好的编程设计并创建几个函数,并执行与此问题的解决方案相关的明确任务。确保非常注意参数传递。特别是在每个需要struct library类型变量的函数中,一定要通过引用传递变量,如下:
void addBook(struct library* thislib);
这将确保对函数中的库所做的任何更改都会反映在 main.js 中。在像这样的函数中,请记住访问任一组件,使用以下表达式:
thislib->collection
thislib->num_books
每当您将一本书添加到集合中时,请确保将其添加到集合的末尾。不要忘记更新 struct library 变量中的变量 num_books。 每当您从收藏中删除一本书时,请确保将倒数第二个插槽中的书复制到空出的位置。例如,如果要删除的书在位置 3,并且删除前集合中的书数为 7,则位置 6(倒数第二个填充位置)的书应移动到索引 3 中的书。随后,图书馆的图书数量应更新为仅可容纳 6 本。
以下是我到目前为止所做的,
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void viewBooks()
{
int found = 0;
char bookName[MAX_BOOK_NAME] = {0};
{
s_BooksInfo_addBookInfoInDataBase = {0};
FILE *fp = NULL;
int status = 0;
unsigned int countBook = 1;
headMessage("VIEW BOOKS DETAILS");
fp = fopen(FILE_NAME,"rb");
if(fp == NULL)
{
printf("File is not opened\n");
exit(1);
}
if (fseek(fp,FILE_HEADER_SIZE,SEEK_SET) != 0)
{
fclose(fp);
printf("Facing issue while reading file\n");
exit(1);
}
while (fread (&addBookInfoInDataBase, sizeof(addBookInfoInDataBase), 1, fp))
{
printf("\n\t\t\tBook Count = %d\n\n",countBook);
printf("\t\t\tBook id = %u",addBookInfoInDataBase.books_id);
printf("\n\t\t\tBook name = %s",addBookInfoInDataBase.bookName);
printf("\t\t\tBook authorName = %s",addBookInfoInDataBase.authorName);
printf("\t\t\tBook issue date(day/month/year) = (%d/%d/%d)",addBookInfoInDataBase.bookIssueDate.dd,
addBookInfoInDataBase.bookIssueDate.mm, addBookInfoInDataBase.bookIssueDate.yyyy);
found = 1;
++countBook;
}
fclose(fp);
if(!found)
{
printf("\n\t\t\tNo Record");
}
printf("\n\n\t\t\tPress any key to go to main menu.....");
fflush(stdin);
getchar();
}
return 0;
}
【问题讨论】:
-
如果我理解正确,
error:'MAX_BOOK_NAME' undeclared (first use in this function)是你的问题,对吧?? -
什么是
MAX_BOOK_NAME?它是在哪里定义的? -
除了这个问题(可以用更小的minimal reproducible example 浓缩成一个更短的问题),您显示的代码还有其他问题。请花一些时间阅读the help pages,阅读SO tour,阅读How to Ask,以及this question checklist。最后请学习如何edit你的问题来改进它。
-
看起来你必须做一个电脑练习,然后在这里复制/粘贴整个内容。
标签: c