After 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.
// 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;
}
make clean
and thenmake speller
.