0

enter image description hereI've almost given up. I literally cannot figure out what's the issue. I can't even debug my code for issues because this command error keeps coming up. Please, help me and be straight forward I'm tired of spending time on this.

// Implements a dictionary's functionality

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "dictionary.h"
// Represents number of children for each node in a trie
#define N 27

// Represents a node in a trie
typedef struct node
{
    bool is_word;
    struct node *letters[N];
}
node;
// Represents a trie//topmost node
node *root = NULL;


//to keep track of number of words in the dictionary
int dictionNum = 0;

//prototypes
int index_char(char c);
node *getnode(void);
node *root;

// Returns true if word is in dictionary else false
bool check(const char *word)
{
    node *t = root;
    int index;
// to check each letter in the input word
    for(int i = 0, n = strlen(word); i < n; i++){

        index = index_char(word[i])
        if(!t->letters[index]){
            return false;
        }

        t = t ->children[index];
    }
    return t->is_word;
}


// Loads dictionary into memory, returning true if successful else false
bool load(const char *dictionary)
{
    // Open dictionary
    FILE *file_ptr = fopen(dictionary, "r");
    if (file_ptr == NULL)
    {
        fprintf(stderr, "File does not exist\n");
        unload();
        return false;
    }

    // Initialize trie
    //root = malloc(sizeof(node));//if NULL, malloc a new node
    // need a node that will traverse through the trie
    root = getnode();
    node *t = root;

    // an array to story the word from the dictionary
    char word[LENGTH];

    // Insert words into trie
    while (fscanf(file_ptr, "%s", word) != EOF)
    {
        int index;
        //iterate over the letters of the word in order to create an index
        for(int i = 0, n = strlen(word); i<n ; i++){

            if(word[i] == '\n'){
                //at the end of the line you have hit the end of a word
                //have to round it out so it can go back to the root
                t ->is_word = true;
                t = root;
                dictionNum ++; //increment for every word in the dictionary
                continue
            }
            index = index_char(cord[i]);

            if(!head->lettters[index]){
                t->letters[index]=getnode();
            }

            t = t ->letters[index];
        }
    }

    // Close dictionary
    fclose(file_ptr);

    // Indicate success
    return true;
}

// Returns number of words in dictionary if loaded else 0 if not yet loaded
unsigned int size(void)
{
    return dictionNum;
}


// Unloads dictionary from memory, returning true if successful else false
bool unload(void)
{

    node *ptr = root;
    while(!ptr){
        //temporary Node to store the header of the list
        node *next = ptr;
        free(ptr);
        ptr = next;
    }
    return true;
}

node *getnode(void){
    root = NULL;
    root = malloc(sizeof(node));
    if(root){
        root->is_word = false;

        for(int i = 0; i < N; i++){
            root->children[i]=NULL;
        }
    }
    return root;
}

int index_char(char c){

    if(c == '\'){
        return 26;
    }
    else if(c >= 'A' && c<='Z'){
        return c-65;[![enter image description here][1]][1]
    }
    else{
        return c-97;
    }
}
0
0

I see the current problem. You have no file named Makefile in the current directory. It has all the build instructions that the compiler needs to build a program using multiple source code files. Without it, the compiler doesn't know to use dictionary.h and dictionary.c.

You need to extract the makefile from the distro zip file (see pset instructions). My suggestion would be to save your dictionary.c file in another directory, re-extract all the files for the pset, then copy your work file back to this directory.

Then, try again! ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.