当我将结构传递给函数时,我得到错误:期望'struct book'但是参数是'struct book'类型.为什么会这样?
#include
#include
struct book
{
int id;
char title[50];
};
int showBooks(struct book x);
int main()
{
struct book
{
int id;
char title[50];
};
struct book book1,book2;
book1.id = 2;
book2.id = 3;
strcpy(book1.title, "c programming");
strcpy(book2.title, "libc refrence");
printf("Book\t\tID\n");
showBooks(book1);
showBooks(book2);
}
int showBooks(struct book x)
{
printf("%s\t%d\n", x.title, x.id);
}
错误:
30:12:错误:"showBooks"
showBooks(book1)的参数1的不兼容类型;
10:5:注意:预期的'struct book'但是参数类型为'struct book'int showBooks(struct book x);
31:12:错误:"showBooks"
showBooks(book2)的参数1的不兼容类型;
10:5:注意:预期的'struct book'但是参数类型为'struct book'int showBooks(struct book x);
这里的错误在哪里?