gpt4 book ai didi

C 结构问题

转载 作者:行者123 更新时间:2023-11-30 15:26:38 25 4
gpt4 key购买 nike

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

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

最佳答案

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);

不要添加结构

关于C 结构问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27319142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com