这是我的主要功能。它说它到达readRecord函数的末尾并且没有获得返回类型?错误如下。我正在返回一个名为Movie的typedef结构。它在support.h中定义,并在readRecord函数中列出了下面列出的变量。我已经尝试在support.h中定义readRecord但它没有帮助。
#include <stdlib.h>
#include <stdio.h>
#include "scanner.h"
#include "support.h"
Movie *readRecord(FILE*);
main(int argc, char** argv)
{
FILE *fp = fopen("test.xlt", "r");
readRecord(fp);
return 0;
}
Movie *
readRecord(FILE *fp)
{
char *name;
name = readString(fp);
if(feof(fp)) {return 0;}
Movie *m = malloc(sizeof(Movie));
m->name = name;
m->description = readString(fp);
m->year = readInt(fp);
m->length = readInt(fp);
m->rating = readToken(fp);
m->cast = readString(fp);
m->director = readString(fp);
return Movie *;
}
在终端:
$ gcc -Wall -g level1.c scanner.c -o level1
level1.c: In function ‘readRecord’:
level1.c:35:12: error: expected expression before ‘Movie’
return Movie *;
^
level1.c:36:5: warning: control reaches end of non-void function [-Wreturn-type]
}
^
答案 0 :(得分:0)
您希望在变量m
中返回对象,而不是类型Movie *
,即。
return m;