I am having troubles with the check function in dictionary.c in pset5.
Here is my code:
/**
* dictionary.c
*
* Computer Science 50
* Problem Set 5
*
* Implements a dictionary's functionality.
*/
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include "dictionary.h"
/**
* Returns true if word is in dictionary else false.
*/
bool check(const char* word)
{
node* cursor = root;
bool isLastLetter = false;
for (int i = 0; i < strlen(word); i++) {
if (isLastLetter) {
if (strcmp((word + i), "\'") == 0) {
if (cursor->children[0] == NULL) {
return false;
}
else {
if (cursor->children[0]->isWord == true)
return true;
}
}
else if (isupper((char)*(word + i))) {
else if (cursor->children[(int)*(word + i) - 64] == NULL) {
return false;
}
else if (cursor->children[(int)*(word + i) - 64]->isWord == true) {
return true;
}
else {
return false;
}
}
else {
else if (cursor->children[(int)*(word + i) - 96] == NULL) {
return false;
}
else if (cursor->children[(int)*(word + i) - 96]->isWord == true) {
return true;
}
else {
return false;
}
}
}
else {
if (strcmp((word + i), "\'") == 0) {
if ((cursor->children[0]) == NULL) {
return false;
}
else {
cursor = cursor->children[0];
}
}
else if (isupper((char)*(word + i))) {
else if (cursor->children[(int)*(word + i) - 64] == NULL) {
return false;
}
else if (cursor->children[(int)*(word + i) - 64] != NULL) {
cursor = cursor->children[(int)*(word + i) - 96];
}
}
else {
else if (cursor->children[(int)*(word + i) - 96] == NULL) {
return false;
}
else if (cursor->children[(int)*(word + i) - 96] != NULL) {
cursor = cursor->children[(int)*(word + i) - 96];
}
}
}
if (i == strlen(word) - 2) {
isLastLetter = true;
}
}
return false;
}
void setLetter(node* cursor, int letter, bool is_w) {
if (cursor->children[letter] == NULL) {
cursor->children[letter] = malloc(sizeof(node));
cursor->children[letter]->isWord = is_w;
return;
}
cursor->children[letter]->isWord = is_w;
}
Here are my errors:
clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -c -o dictionary.o dictionary.c
dictionary.c:38:17: error: expected expression
else if (cursor -> children[(int)*(word + i) - 64] == NULL) {
^
dictionary.c:49:17: error: expected expression
else if (cursor -> children[(int)*(word + i) - 96] == NULL) {
^
dictionary.c:72:17: error: expected expression
else if (cursor -> children[(int)*(word + i) - 64] == NULL) {
^
dictionary.c:80:17: error: expected expression
else if (cursor -> children[(int)*(word + i) - 96] == NULL) {
^
4 errors generated.
make: *** [dictionary.o] Error 1
Please help me. Thank-you very much!
Jon
if
statements andfor/while/do-while
loops. It's going to save you a lot of trouble with bugs, and it's going to make your code much more readable, especially to you.