我正在用指针挣扎一下。我试图在函数之间传递信息,但得到以下错误:“请求成员”得分“的东西不是一个结构或联盟”,和“索引”而不是得分相同的错误(和所有其他成员我这样做并没有在这里列出)。使用struct在函数之间传递数组信息
这里是我的结构:
typedef struct line_t {
char* buf;
int lineLength;
int wordCount;
int index;
double score;
} line_t;
这是我的调用函数在main(与报关):
line_t bestmatch[TOP_SCORING_MAX];
func3(&line, &bestmatch[TOP_SCORING_MAX]);
这里是我的功能:
line_t
func3(line_t line, line_t *bestmatchPtr[]) {
int i;
for (i=0; i< TOP_SCORING_MAX; i++) {
if (line.score != 0) {
if (i == 0) {
bestmatchPtr[0].score = line.score;
bestmatchPtr[0].index = line.index;
/*more code here: rest of func, closing of }, etc*/
return bestmatchPtr;
}
本质,我需要传递有关函数间bestmatch的信息,同时保持它的顺序(我的函数试图订购信息只保留一定数量的数据)。我想知道如何解决这个错误? 如果我遗失了一些信息,请告诉我。
一些编译器不能通过结构或归还。尝试使retutn值为line_t *,同上参数行。请记住使用 - >运算符而不是要求元素。 – rhubarbdog 2014-09-23 10:33:50