Please help me figure this problem out. The program outputs around 14000 words out of the 19000 words in austinpowers.
Here is my code:
int getSpot(int letter, node* cursor) {
if (cursor->children[letter] == NULL) {
cursor->children[letter] = malloc(sizeof(node));
}
return 0;
}
bool check(const char* word)
{
node* cursor = root;
for (int i = 0; i < strlen(word); i++) {
int letter = (int)*(word + i);
if (letter >= 65 && letter < 96) {
letter += 32;
}
if (letter == 39) {
if (cursor->children[0] == NULL) {
return false;
}
}
else if (cursor->children[letter - 96] == NULL) {
return false;
}
if (letter == 39) {
cursor = cursor->children[0];
} else {
cursor = cursor->children[letter - 96];
}
}
return cursor->isWord;
}
/**
* Loads dictionary into memory. Returns true if successful else false.
*/
bool load(const char* dictionary)
{
FILE* file = fopen(dictionary, "r");
if (file == NULL) {
return false;
}
char word[LENGTH + 1];
root = malloc(sizeof(node));
node* cursor = root;
while (true) {
for (int i = 0; i <= LENGTH; i++) {
word[i] = (char)(0x00);
}
fscanf(file, "%s", word);
if (feof(file) != 0) {
break;
}
for (int i = 0; i < strlen(word); i++) {
if ((int)word[i] == 39) {
getSpot(0, cursor);
cursor = cursor->children[0];
}
else {
getSpot((int)(word[i]) - 96, cursor);
cursor = cursor->children[(int)(word[i]) - 96];
}
}
SIZEofTABLE++;
cursor->isWord = true;
}
return true;
}
/**
* Returns number of words in dictionary if loaded else 0 if not yet loaded.
*/
unsigned int size(void)
{
// TODO
return SIZEofTABLE;
}
/**
* Unloads dictionary from memory. Returns true if successful else false.
*/
bool unload(void)
{
// TODO
SIZEofTABLE = 0;
return true;
}`
Thank-you in advance!!
Jon