将指针解除引用为不完整类型

时间:2014-12-08 17:09:29

标签: c struct

我已经在这里待了几个小时,无法弄清楚这可能是一个愚蠢的错误。以下是错误:

crawler.c:8: error: dereferencing pointer to incomplete type

crawler.c:9: error: dereferencing pointer to incomplete type

crawler.c:10: warning: return from incompatible pointer type

代码是:

//--------------------------Header File----------------------------------//
#ifndef CRAWLER_H 
#define CRAWLER_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "indexPage.h"
struct pointersWordControl{
    queryHelper **queryArray;
    char** URLs;
};
typedef struct pointersWordControl queryHelperExt;
queryHelperExt  *crawler(const char* FILE_NAME, const int MAX_N);
#endif  

//---------------------------------Crawler.c-------------------------------//
queryHelperExt *crawler(const char* FILE_NAME, const int Max_N)
{

    queryHelper **structArray = malloc(sizeof(struct wordControl*)*50); 
    char** urlString;
    urlString= missionControl(FILE_NAME, Max_N, structArray);
    struct queryHelperExt *queryPass=malloc(sizeof(struct pointersWordControl)*1);
    queryPass->queryArray=structArray;
    queryPass->URLs=urlString; 
    return queryPass;
}

2 个答案:

答案 0 :(得分:4)

更改

struct queryHelperExt *queryPass=malloc(sizeof(struct pointersWordControl)*1);

queryHelperExt *queryPass=malloc(sizeof(struct pointersWordControl)*1);

没有struct queryHelperExt - 标识符queryHelperExtstruct pointersWordControl的typedef,并且不需要struct键工作。

答案 1 :(得分:3)

您的问题是,您声明queryPass类型struct queryHelperExtqueryHelperExt的预期类型不同。在C中,添加struct关键字使其成为不同的类型(与C ++不同)。