Can somebody please help me whenever i execute check50 on my code i get this
:( handles most basic words properly
expected "MISSPELLED WORD...", not "MISSPELLED WORD..."
:( handles min length (1-char) words
expected "MISSPELLED WORD...", not "MISSPELLED WORD..."
:( handles max length (45-char) words
expected "MISSPELLED WORD...", not "MISSPELLED WORD..."
:( handles words with apostrophes properly
expected "MISSPELLED WORD...", not "MISSPELLED WORD..."
:( spell-checking is case-insensitive
expected "MISSPELLED WORD...", not "MISSPELLED WORD..."
:( handles substrings properly
expected "MISSPELLED WORD...", not "MISSPELLED WORD..."
:| program is free of memory errors
can't check until a frown turns upside down
my code:
// Implements a dictionary's functionality
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <strings.h>
#include <string.h>
#include <stdlib.h>
#include "dictionary.h"
// Represents number of buckets in a hash table
#define N 26
int quantity = 0;
// Represents a node in a hash table
typedef struct node
{
char word[LENGTH + 1];
struct node *next;
}
node;
// Represents a hash table
node *hashtable[N];
// Hashes word to a number between 0 and 25, inclusive, based on its first letter
unsigned int hash(const char *word)
{
return tolower(word[0]) - 'a';
}
// Loads dictionary into memory, returning true if successful else false
bool load(const char *dictionary)
{
// Initialize hash table
for (int i = 0; i < N; i++)
{
hashtable[i] = NULL;
}
// Open dictionary
FILE *file = fopen(dictionary, "r");
if (file == NULL)
{
unload();
return false;
}
// Buffer for a word
char word[LENGTH + 1];
node* head = NULL;
// Insert words into hash table
while (fscanf(file, "%s", word) != EOF)
{
int position = hash(word);
node* a_node = malloc(sizeof(node));
if (hashtable[position] == NULL)
{
hashtable[position] = a_node;
strcpy(a_node->word , word);
a_node->next = NULL;
}
else
{
strcpy(a_node->word,word);
a_node->next = hashtable[position];
hashtable[position] = a_node;
}
quantity++;
}
// Close dictionary
fclose(file);
// Indicate success
return true;
}
// Returns number of words in dictionary if loaded else 0 if not yet loaded
unsigned int size(void)
{
if (quantity != 0)
{
return quantity;
}
else
{
return 0;
}
}
// Returns true if word is in dictionary else false
bool check(const char *word)
{
int position = hash(word);
node* temp = malloc(sizeof(node));
temp = hashtable[position];
if(temp->next != NULL)
{
while(strcasecmp(temp->word , word) != 0)
{
temp = temp->next;
}
return true;
}
else
{
return false;
}
}
// Unloads dictionary from memory, returning true if successful else false
bool unload(void)
{
node *start = malloc(sizeof(node));
for (int i = 0; i < N; i++)
{
start = hashtable[i];
node *move = start;
while (move != NULL)
{
node *temp = move;
move = move->next;
free(temp);
}
}
free(start);
return true;
}