I've been working a few days in speller and I've managed to make it work exactly like the cs50 staff's (or at least it looks exactly) But check50 says everything is wrong except compiling:
:) dictionary.c, dictionary.h, and Makefile exist
:) speller compiles
:( handles most basic words properly expected "MISSPELLED WOR...", not "MISSPELLED WOR..."
:( handles min length (1-char) words expected "MISSPELLED WOR...", not "MISSPELLED WOR..."
:( handles max length (45-char) words expected "MISSPELLED WOR...", not "MISSPELLED WOR..."
:( handles words with apostrophes properly expected "MISSPELLED WOR...", not "MISSPELLED WOR..."
:( spell-checking is case-insensitive expected "MISSPELLED WOR...", not "MISSPELLED WOR..."
:( handles substrings properly expected "MISSPELLED WOR...", not "MISSPELLED WOR..."
:| program is free of memory errors can't check until a frown turns upside down
this is the code I'm using:
check:
bool check(const char *word)
int h = hash(word);
node *tmp = table[h];
while (true)
{
if (strcasecmp (word, tmp->word) == 0)
{
return true;
}
else if (tmp->next != NULL)
{
tmp = tmp->next;
}
else if (tmp->next == NULL)
{
return false;
}
}
return false; }
hash:
unsigned int hash(const char *word)
{ //Hash function "djb2" by Dan Bernstein
unsigned long hash = 5381;
int l = strlen(word);
char lowerword[l+1];
for (int i = 0; i<l; i++)
{
lowerword[i] = tolower(word[i]);
}
for (int i = 0; i<l; word++, i++)
{
hash = ((hash<<5) + hash) + *lowerword;
}
if (hash >= N)
{
return hash % N;
}
else
{
return hash;
}
}
load:
bool load(const char *dictionary)
{
char word[LENGTH+1];
int h = 0;
FILE *file = fopen(dictionary, "r");
if (file == NULL)
{
printf ("Could not load\n");
return 1;
}
while (fscanf (file, "%s", word) != EOF)
{
node *n = malloc(sizeof(node));
if (n == NULL)
{
printf ("Could not load\n");
return 1;
}
strcpy(n->word, word);
sizetable++;
n->next = NULL;
h = hash(word);
node *tmp = table[h];
n->next = table[h];
table[h] = n;
}
fclose (file); return true; }
unload:
node *clear = NULL;
node *tmp = NULL;
for (int i = 0;i
clear = table[i];
while(clear->next != NULL)
{
tmp = clear;
clear = clear->next;
free(tmp);
}
tmp = clear;
free(tmp);
}
return true;
sorry for that for loop, I can't put it right, here is the rest:
for (int i = 0;i lower than N;i++)
that´s in detail what check50 says:
https://submit.cs50.io/check50/cccb469293f9de280e1a76400c9d0d645982859d
I would truly appreciate any help, I'm so close now but I can't find the last mistake. Thanks!