我使用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)