【发布时间】:2016-12-11 12:06:05
【问题描述】:
我正在编写一个程序来使用 typedef 和 function 输入书籍信息。
这是我使用 typedef 的声明:
typedef struct {
char name[1000], author[1000], publisher[1000], description[1000], ISBN[15];
} book;
添加图书信息的函数如下:
void addBook(int* n, book list[1000]) {
printf("Enter number of book you want to add: ");
fpurge(stdin);
scanf("%d", n);
int i;
for (i = 0; i < *n; i++) {
printf("Book title: ");
fpurge(stdin);
gets(list[i].name);
printf("Book author: ");
fpurge(stdin);
gets(list[i].author);
printf("Publisher: ");
fpurge(stdin);
gets(list[i].publisher);
printf("Description: ");
fpurge(stdin);
gets(list[i].description);
printf("ISBN: ");
fpurge(stdin);
gets(list[i].ISBN);
}
}
最后是主要的:
int main(int argc, char** argv) {
int n, list[1000];
addBook(&n, list);
return (EXIT_SUCCESS);
}
所以当我尝试运行时,它起作用了。但是,编译器向我显示了两个警告:
警告:从不兼容的指针类型 [-Wincompatible-pointer-types] 传递“addBook”的参数 2
预期为“book *”,但参数的类型为“int”
我的问题是:这些警告是否被视为错误?如果是,正确的解决方案是什么?如果不是,为什么编译器显示它?
P/s:我使用的是 Netbean IDE。
【问题讨论】:
标签: c arrays function pointers typedef