0
bool load(const char* dictionary)
{
int counter = 0;
int hash = 0;

// define node data type for linked list
typedef struct node
{
    char word[LENGTH + 1];
    struct node* next;
}
node;


// declare the hash table
node* hash_table[27];


// loop through each dictionary word
while (!=EOF)
{

    // create new node
    node* new_node = malloc(sizeof(node));

    new_node -> next = NULL;

    // check for NULL
    if (new_node == NULL)
    {
        exit(1);
    }


    // read in dictionary word
    fscanf(dictionary, "%s", new_node -> word);

    //increment dictionary word count
    counter++;

    // hash dictionary word
    int hash = toupper(new_node -> word[0]) - 'A';

    // insert word into hash table


    hash_table[hash] = new_node -> next;
    new_node -> next = hash_table[hash] -> next;
    hash_table[hash] -> next = new_node -> next;

}




return false;
}

these are my errors

dictionary.c:47:12: error: expected expression
while (!=EOF)
       ^
dictionary.c:63:16: error: incompatible pointer types passing 'const char *' to parameter of type 'FILE *'
  (aka 'struct _IO_FILE *') [-Werror,-Wincompatible-pointer-types]
    fscanf(dictionary, "%s", new_node -> word);
           ^~~~~~~~~~
/usr/include/stdio.h:443:50: note: passing argument to parameter '__stream' here
extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
                                             ^
/usr/include/x86_64-linux-gnu/sys/cdefs.h:178:46: note: expanded from macro '__REDIRECT'
# define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))

1 Answer 1

1

Lots of syntax errors.

while (!=EOF)

The "not equal to" operator, !=, operates on two values or variables, comparing them. This statement has one value, EOF. The correct operator would be the not operator, !.

fscanf(dictionary, "%s", new_node -> word);

dictionary is a constant character string, the file name, not a file pointer. I'll leave it to you to read the documentation on fscanf to figure out how to fix this.

Later errors may be side effects of the fscanf problem.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .