2014-12-05 98 views
0

這是我正在處理的網絡搜索引擎的一部分。基本上,我試圖存儲索引URL上的所有單詞以及單詞發生次數。當然,我制定了一個結構來存儲這兩件事。在函數indexMyStuff我malloc空間的結構和它的內容。然後我繼續將它傳遞給printTrieContents,它負責將數據添加到結構中。我得到這些錯誤:我只包含這兩個函數,以避免一個瘋狂的冗長的職位。C結構問題

[email protected]:~/project5$ make 
gcc -g -c indexPage.c -o indexPage.o 
In file included from indexPage.c:12: 
indexPage.h:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token 
indexPage.c:77: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token 
indexPage.c: In function ‘indexMyStuff’: 
indexPage.c:147: error: dereferencing pointer to incomplete type 
indexPage.c:148: error: dereferencing pointer to incomplete type 
indexPage.c:152: error: void value not ignored as it ought to be 
indexPage.c: At top level: 
indexPage.c:263: error: conflicting types for ‘printTrieContents’ 
indexPage.c:151: note: previous implicit declaration of ‘printTrieContents’ was here 
indexPage.c: In function ‘printTrieContents’: 
indexPage.c:291: error: too few arguments to function ‘printTrieContents’ 
make: *** [indexPage.o] Error 1 


typedef struct wordControl queryHelper; 
struct wordControl{ 
    char** words; 
    int* countArry; 
}; 

queryHelper *indexMyStuff(char* argv) { 



    struct queryHelper *myStruct = malloc(sizeof(struct wordControl)*1); 
    myStruct->words=malloc(sizeof(char*)*100); 
    myStruct->countArry=malloc(sizeof(int)*100); 

    trieIndex_t *myTrie = indexPage(argv); 
    printTrieContents(myTrie, "",myStruct); 
    return freeTrieMemory(myTrie); 


} 

queryHelper *printTrieContents(trieIndex_t *pNode, char oldBuffer[MAX_WORD_SIZE], queryHelper *structure) { 
// Alphabet counter 
    int i = 0; 
    // The new buffer that contains the concatenated string 
    char newBuffer[MAX_WORD_SIZE]; 

    // Now, lets step through each of the characters. It is worthy to note that this 
    // will work in alphabetical order, since the code starts counting from 0-25, and 
    // each letter is stored in the character array as a mapping from a = 0 to z = 25, 
    // this will automatically display them in aplhabetical order. 
    for (i = 0; i < ALPHA_SIZE; i++) { 
    // Check if the ith character is not null 
    if (pNode->children[i] != NULL) { 

    // Now we concatenate the character at the end of the existing string 
    snprintf(newBuffer, MAX_WORD_SIZE, "%s%c", oldBuffer, intToAlpha(i)); 

    // If the current string is actually a word that was found in the indexing 
    // process, we will print it here, as well as the amount of times that the 
    // indexing function found the word. 
    if (pNode->children[i]->count > 0) { 
    structure->words[i]=newBuffer; 
    structure->countArry[i]=pNode->children[i]->count; 

    } 

    // Recurse through all the characters until we reach the leaves of every 
    // one of the branches. 
    printTrieContents(pNode->children[i], newBuffer); 

    } 
} 
return structure; 
} 





    //-----------------------------HEADER FILE--------------------------------------// 
    #ifndef INDEX_H 
    #define INDEX_H 
    #include <stdlib.h> 
    #include <stdio.h> 
    #include <string.h> 
    #include <ctype.h> 

    queryHelper *indexMyStuff(char* argv); 
    #endif 
+0

初始編譯器錯誤在indexPage.h中。請提供此文件並明確如何包含/ – 2014-12-05 15:25:55

+0

我只是將它包含在底部。 – sudoMan13 2014-12-05 15:35:30

+0

問問你自己,在編譯你的頭文件之前,編譯器知道'queryHelper'是什麼?*爲這個ID提供任何定義之前? – WhozCraig 2014-12-05 15:52:17

回答

1
indexPage.h:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token 

看看該行:

queryHelper *indexMyStuff(char* argv); 

什麼queryHelper?編譯器不知道。這是錯誤信息,但是這是因爲編譯器不知道它是什麼類型。您需要將typedef移動到標題(在該行上方)。

而接下來的錯誤:

indexPage.c:77: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token 

你不包括線(或告訴我們它是),所以我們不能幫你上

indexPage.c: In function ‘indexMyStuff’: 
indexPage.c:147: error: dereferencing pointer to incomplete type 
indexPage.c:148: error: dereferencing pointer to incomplete type 
indexPage.c:152: error: void value not ignored as it ought to be 

struct queryHelper *myStruct = malloc(sizeof(struct wordControl)*1); 
myStruct->words=malloc(sizeof(char*)*100); 
myStruct->countArry=malloc(sizeof(int)*100); 

請勿添加struct