C结构问题

时间:2014-12-05 15:21:40

标签: c web struct

这是我正在处理的网络搜索引擎的一部分。基本上我试图存储索引URL上找到的所有单词以及单词出现次数的计数。当然,我制作了一个存储这两件事的结构。在函数indexMyStuff中我为malloc空间提供结构及其内容。然后我继续将它传递给printTrieContents,它负责将数据添加到Structure。我收到了这些错误:我只包括这两个功能,以避免疯狂冗长的帖子。

aldrbw01@timber:~/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

1 个答案:

答案 0 :(得分: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

on

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

不要添加struct