I apologize but I am so lost. I have watched the videos over and over, read and reread the recommended material but am unable to figure this out. I hesitate to even post my code as it likely has so many flaws one wouldn't even know where to begin helping me.
I think my primary issue is not understanding how to get the info into my root or temp pointer. If using fgetc gets me to the location how do I grab the data that is there?
Thanks in advance.
bool load(const char* dictionary)
{
FILE* fp = fopen(dictionary, "r");
if(fp == NULL)
{
printf("Unable to open dictionary.\n");
return false;
}
node* root = malloc(sizeof(node));
node* trav = root;
for (char c = fgetc(fp); c !=EOF; c = fgetc(fp))
{
for (int i = 0; i < LENGTH; i++)
{
if (c == '\n')
{
root->is_word = true;
word_count++;
return true;
}
if (c == EOF)
{
root->is_word = true;
word_count++;
break;
}
else
{
node* temp = malloc(sizeof(node));
trav->child[i] = temp;
}
}
}
fclose(fp);
return true;
}
EDIT: I have mode a few changes but am unsure how to make sure it's actually loading.
bool load(const char* dictionary)
{
FILE* fp = fopen(dictionary, "r");
if(fp == NULL)
{
printf("Unable to open dictionary.\n");
return false;
}
root = calloc(1, sizeof(node));
node* trav = root;
int index = 0;
for (char c = fgetc(fp); c != EOF; c = fgetc(fp))
{
if (root->child[index] == NULL)
{
root->child[index] = calloc(1, sizeof(node));
}
else
{
if (c == '\'')
{
index = 26;
}
if (c == '\n')
{
trav->is_word = true;
word_count++;
trav = root;
}
if (trav->child[index] == NULL)
{
trav->child[index] = calloc(1, sizeof(node));
trav = trav->child[index];
index++;
}
else
{
trav = trav->child[index];
index++;
}
}
}
fclose(fp);
return true;
}