Hello
I'm doing a C algorithm work and stopped at one part. The program has to read from an input file and insert it into an n-ary Trie tree.
The code that le le of the file is this:
int abre_arquivo(TRIE_N ** root) {
FILE* arquivo;
char* word;
arquivo = fopen("dicionario.txt", "r");
if (arquivo == NULL)
printf("Arquivo não pode ser aberto.\n");
else {
while ((fscanf(arquivo, "%s\n", word)) != EOF) {
insertTrie(&(*root), word);
}
}
fclose(arquivo);
return 0;
}
The insertTrie function header is:
int insertTrie(TRIE_N ** root, char * word)
I wanted to know how to call the insertTrie function inside the open_file correctly. I used gdb and it's giving segmentation failure on line
current = &(*root)->children[word[0]-97];
of insertTrie. If you have any other errors in the function, I would also like to know.
Thank you