0
bool load(const char *dictionary)
{
    // Open dictionary
    FILE *dict = fopen(dictionary, "r");
    if (dict == NULL)
    {
        printf("Could not read.\n");
        return false;
    }

    char dict_word[LENGTH + 1];

    char *string = NULL;

    int length;

    // Index for Linked List
    int index;

    // Read from dict while lopping and copy to dict_word
    while(fscanf(dict, "%s", dict_word) != EOF)
    {

        // Get length of word
        for (int i = 0; i < LENGTH + 2; i++)
        {
            if (dict_word[i] == '\0')
            {
                length = i;
            }
            else
            {
                continue;
            }
        }

        // Get word in string format
        for (int i = 0; i < length + 1; i++)
        {
            string = malloc((length + 1) * sizeof(char *));

            if (string == NULL)
            {
                unload();
                printf("NOT ENOUGHT MEMORY!\n");
                return false;
            }

            string[i] = dict_word[i];
        }

        // Copy word from string to node 
        for (int i = 0; i < (length + 1); i++)
        {
            // Create Node
            node *n = malloc(sizeof(node));
            if (n == NULL)
            {
                unload();
                printf("NOT ENOUGH MEMORY!\n");
                return false;
            }

            strcpy(n->word, string);
            n->next = NULL: 
        }

        // Hash the word
        index = hash(n->word);

        // Insert hash into Linked List
        node *list = malloc(sizeof(node));
        list->next = &n;

    }

    return false;
}
3
  • IM sorry didn't put anything – l3hargav Mar 24 '20 at 14:06
  • Just want to check if my code is ok for now – l3hargav Mar 24 '20 at 14:06
  • Hi! What is your question here? – Enis Arik Mar 25 '20 at 8:17

You must log in to answer this question.

Browse other questions tagged .