小编Tom*_*Tom的帖子

全局指针值丢失.2个c文件

我使用3个文件制作trie:speller.c是主文件,dictionary.c包含函数和全局根trie指针,dictionary.h声明了字典的函数.在dictionary.c中完成函数加载后,全局根指针值丢失问题.

speller.c

int main(int argc, char* argv[])
{   
    // load dictionary
    char* dictionary = TMPDICT;

    bool loaded = load(dictionary);

    // abort if dictionary not loaded
    if (!loaded)
    {
        printf("Could not load %s.\n", dictionary);
        return 1;
    }

    //next I need to call check function, but root value is missing here

}
Run Code Online (Sandbox Code Playgroud)

dictionary.c

typedef struct TrieNode
    {
      struct TrieNode **children;
      bool is_word;
    } TrieNode;
struct TrieNode * root;


struct TrieNode *create_trienode(char c, struct TrieNode *parent);
bool load(const char* dictionary)
    {

        FILE * …
Run Code Online (Sandbox Code Playgroud)

c pointers global-variables

3
推荐指数
1
解决办法
107
查看次数

标签 统计

c ×1

global-variables ×1

pointers ×1