结构混乱

我想创建一个函数,它获取一本书的标题和作者,如果它可用或不可用则返回0或1,通过将它们与给定的结构数组进行比较…..编译器显示:

structs.c:10:28: error: expected ')' before 'title' structs.c: In function 'main': structs.c:59:21: error: expected expression before 'bookRecord' structs.c:60:13: error: expected expression before 'bookRecord' structs.c:61:9: warning: implicit declaration of function 'requestBook' structs.c:61:23: error: expected expression before 'bookRecord' 

这是代码:

  #include #include  #include  #define TRUE 1 #define FALSE 0 #define NUM_BOOKS 5 int requestBook(bookRecord title[],bookRecord author[]){ /* compiler error :10*/ int i; for(i=0;i<=NUMBOOKS;i++){ if(strcmp(stacks[i].tittle ,bookRecord.title[0]) == 0 && strcmp(stacks[i].author ,bookRecord.author[0]) == 0 ){ return 1; } } return 0; } typedef struct { int minute; int hour; } timeT; typedef struct { char title[50]; char author[50]; int year; int isOut; timeT time; int isBlank; } bookRecord; /* given array of struct */ bookRecord stacks[NUM_BOOKS]= { {"C How To Program", "Deitel", 2006, FALSE, {0, 0}, TRUE} , {"The Old Capital", "Yasunari Kawabata", 1996, FALSE, { 0, 0}, TRUE}, {"", "", 0, FALSE, {0,0}, FALSE}, {"", "", 0, FALSE, {0,0}, FALSE}, {"", "", 0, FALSE, {0,0}, FALSE} }; int main (int argc, char*argv[]) { int t; scanf("%s ",bookRecord.title[0]); /* compiler error :59*/ scanf("%s",bookRecord.author[0]); /* compiler error :60*/ t=requestBook(bookRecord.title[0], bookRecord.author[0]); /* compiler error :61 printf("%d",t); return 0; } 

任何帮助赞赏!

////////////////////////////////////////////////

如果你想看到最终的解决方案,请访问结构混乱(2)它是重复的

////////////////////////////////////////////////

您的代码有几个问题。

  1. requestBook函数中使用它们之后声明结构。
  2. requestBook函数中,您引用了到目前为止未声明的变量stacks
  3. requestBook函数中,您使用bookRecord 类型作为变量。

可能还有更多,但这是我在第一次阅读时能找到的。

编辑:

其他几个问题:

  1. requestBook函数中,你循环一次到很多次 。 请记住,数组索引从零到(number_of_entries – 1)。
  2. 您也可以使用bookRecord类型作为bookRecord中的变量。
  3. 当您错误地使用bookRecord您没有获得结构或字符串,您只能获得字符串titleauthor的第一个字符。

你有这个问题:

if(strcmp(stacks [i] .tittle,bookRecord.title [0])== 0 &&
strcmp(stacks [i] .author,bookRecord.author [0])== 0)

你在第一个strcmp函数中拼错了’title’。