bool load(const char *dictionary)
{
typedef struct node;
{
bool is_word;
struct node *children[27];
}
node;
node *root = malloc(sizeof(node));
bool is_word = false;
//assigning alphabets to children array with ascii values
for (int i = 0; i < 26; i++)
{
children[i] = 97 + i;
}
children[27] = '\'';
FILE *inptr = fopen (argv[1], "r");
if (inptr == NULL)
{
printf("File does not exist.\n");
return 1;
}
char c;
for (c = fgetc(inptr); c != EOF; c = fgetc(inptr))
{
//determining spot in an array
int i = c - ‘a’;
root -> children[i] = malloc(sizeof(node));
if (children[i] == NULL)
{
node *new_children = malloc(sizeof(node));
children[i] -> new_children;
}
else
{
children[i] -> new_children;
}
}
return false;
}
This is what I wrote so far. I am not done with it but I am really confused. How do I put first letter in root? I feel like cs50 lectures and shorts did't really go over the coding stuff on trie.. Thank you.