【发布时间】:2021-07-30 14:12:39
【问题描述】:
有一个错误表明book 未声明,并且有一个注释显示“每个未声明的标识符对于它出现的每个函数只报告一次”。但我不明白为什么它只适用于book.title 而struct 中的其他成员不受影响。
#include<stdio.h>
#include<string.h>
struct LIS
{
char title[75];
char author[75];
char borrower_name[75];
int days_borrowed;
float fine;
};
struct book;
void main() {
int response;
do {
printf("Title of the book: ");
gets(book.title);
printf("Author(s) of the book: ");
gets(book.author);
printf("Name of borrower: ");
gets(book.borrower_name);
printf("Number of days borrowed: ");
scanf("%d", &book.days_borrowed);
if(book.days_borrowed > 3) { book.fine = 5.00 * (book.days_borrowed-3); }
else { book.fine = 0; }
printf("Fine (if applicable): %.2f\n", book.fine);
printf("Enter any key continue/Enter 0 to end: ");
scanf("%d\n", &response);
} while (response != 0);
}
【问题讨论】:
-
struct book;不完整。你的意思是像struct LIS {/* ... */ } book;这样的东西吗?也就是说,您是否尝试在book之前删除; struct?
标签: c struct error-handling compiler-errors structure