#define NUM 10 //用户数量 #define MAX_BOOKS 5 //管理员书单 struct Books_list { int id; //书号 char name[30]; //书名 char author[30]; //作者 char press[30]; //出版社名 }; struct Books_list book1[]={ {1,"唐诗三百首","孙洙","南京大学出版社"}, {2,"三体","刘慈欢","北美权威科幻类出版社"}, {3,"稻草人","叶圣陶","湖南儿童出版社"}, {4,"老人与海","海明威","上海译文出版社"}, {5,"c语言","泰戈尔","浙江文艺出版社"}, };怎么改正
时间: 2023-07-19 13:51:45 浏览: 71
根据您提供的代码,可以看出问题出在定义数组时没有指定数组大小,导致编译器无法确定数组大小,从而出现了错误"elements of array 'Books_list book1[]' have incomplete type"。
要解决这个问题,您需要在定义数组时指定数组大小,例如:
```c++
struct Books_list book1[MAX_BOOKS] = {
{1,"唐诗三百首","孙洙","南京大学出版社"},
{2,"三体","刘慈欢","北美权威科幻类出版社"},
{3,"稻草人","叶圣陶","湖南儿童出版社"},
{4,"老人与海","海明威","上海译文出版社"},
{5,"c语言","泰戈尔","浙江文艺出版社"},
};
```
在这里,我们使用了预定义的常量`MAX_BOOKS`来指定数组大小,并将其初始化为一个包含5个结构体的数组。这样就可以避免上述错误。
阅读全文