0

I am working on the load function of pset 5 speller. My code, however, displays an error message when compliling, that basically looks like this:

(.text+0x20): undefined reference to `main' clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [dictionary] Error 1

I believe it has something to do with the way I implemented my functions, but I do not see a problem. Here's my code below:

    #include <stdbool.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>

    #include "dictionary.h"

    typedef struct node
        {
            bool is_word;
            struct node *children[27];
        }
        node;
        node* root;

    /**
     * Creates a linked list.
     */
    node* create(bool is_word)
    {
        node* new_node = (node*)malloc(sizeof(node));
        if (new_node == NULL)
        {
            exit(0);
        }
        new_node -> is_word = false;
        for (int i = 0; i <= 27; i++)
        {
            new_node -> children[i] = NULL;
        }

        return new_node;
    }

    /**
     * Inserts a new node into the linked list.
     */
    node* insert(node* head, bool is_word)
    {
        node* new_node = create(false);
        head = new_node;
        return head;
    }

    /**
     * Returns true if word is in dictionary else false.
     */
    bool check(const char *word)
    {
        // TODO
        return false;
    }

    /**
     * Loads dictionary into memory. Returns true if successful else false.
     */

    bool load(const char *dictionary)
    {
        FILE* dic = fopen(dictionary, "r");

        if (dic == NULL)
            return false;

        node* head = create(false);
        head = NULL;
        root = head;

        for (int b = fgetc(dic); b != EOF; b = fgetc(dic))
        {
            if (b == '\0')
                head -> is_word = true;
            else if (head -> children[b - 'a'] == NULL)
                head = insert(head -> children[b - 'a'], false);
            else
               head = head -> children[b - 'a']; 
        }
        return true;


    }
2
  • did you "make dictionary" or "make speller" ? – Cliff B Jun 22 '17 at 4:41
  • @CliffB No I'm using "make dictionary," I'm sure of it. – Jason_V Jun 22 '17 at 14:28
1

I found out my problem. After a closer look at the Makefile, I realized that I only needed to type "make" into the terminal to compile all programs in speller, not make dictionary as I was doing.

You must log in to answer this question.

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