我想打一个函数,它接受的标题和一书的作者,并返回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<stdio.h>
#include <stdlib.h>
#include <string.h>
#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;
}
任何帮助表示赞赏!
////////////////////////////////////////////////
如果你想看到的最终的溶液请访问STRUCT惑(2)其DUPLICATE
////////////////////////////////////////////////