0
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.

1

You may try hash tables helpful for implementation of the load function and let me know which part of trie did you not understan. If this helps, please put a check mark on my answer keeping up the forum maintenance!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .