Skip to main content
added 243 characters in body
Source Link

enter image description hereAfter I gotcompile dictionary.c, the errordictionary.o and speller.o show up in the file format unsupportedholder. I doulbe click to open both files, and cannot figure out whereit shows the problem iserror:file format unsupported. Can Also, when I run ./speller texts/lalaland.txt, it shows could not open text. Can somebody please help me, how I can fix it? thanksThank you.

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

enter image description hereAfter I compile dictionary.c, the dictionary.o and speller.o show up in the file holder. I doulbe click to open both files, and it shows the error:file format unsupported. Also, when I run ./speller texts/lalaland.txt, it shows could not open text. Can somebody help me, how I can fix it? Thank you.

added 10 characters in body
Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

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

// 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;


}

// 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;


}
// 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;


}
Source Link

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;


}