Skip to main content
2 of 3
added 10 characters in body
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

pset5 speller dictionary.o : file format unsupported

I got the error file format unsupported and cannot figure out where the problem is. Can somebody please help me? thanks

// Default dictionary
#define DICTIONARY "dictionaries/large"


typedef struct node
{
   char word[LENGTH + 1];
   struct node *next;
}
node;

#define hashtable 26
//  26 buckets
node *bucket[hashtable]; //*

//prototype
int strcasecmp(const char *, const char *);

//hash function
int hash(const char* word);

int wordCount = 0;

 // Returns true if word is in dictionary else false
bool check(const char *word)
{

int num = hash(word);
node *cursor = bucket[num];

    while(cursor != NULL)
    {

        if (strcasecmp(word, cursor -> word ) == 0)
        {
            return true;
        }

    }

    // TODO
    return false;
}


// Loads dictionary into memory, returning true if successful else false
bool load(const char *dictionary)
{
    char word [LENGTH + 1];

    //open dictionary
    FILE *dicptr = fopen(dictionary, "r");
    if(dicptr == NULL)
    {
        return 1;
    }

    //scan dictionary word by word
    while(fscanf(dicptr, "%s\n", word) != EOF) //small dic or large dic? //%s\n,%c
    {

        // new word
        node *new_node = malloc(sizeof(node));


        if(new_node == NULL)
        {
            unload();
            return false;
        }
        else
        {
            //copy word into node
            strcpy(new_node -> word, word);
            wordCount ++;
            //initialize new node
            new_node -> next = NULL;
        }

        int number = hash(word);

        // if the hashtable is still empty
        if(bucket[number] == NULL)
        {
            bucket[number] = new_node;
            new_node -> next = NULL;
        }
        // if the hashtable already has word
        else
        {
            new_node -> next = bucket[0]; //->next
            bucket[number] = new_node;
        }

    }


    //todo
    return true;

}



int hash(const char* word)
{
    int index = 0;
    tolower(word[0]);
    index = word[0] - 'a';

    return index % hashtable;


}