Question: I need help getting rid of these errors in my code. dictionary.c:47:17: error: implicit declaration of function 'hash' is invalid in C99 [-Werror,-Wimplicit-function-declaration] int index
I need help getting rid of these errors in my code. dictionary.c:47:17: error: implicit declaration of function 'hash' is invalid in C99 [-Werror,-Wimplicit-function-declaration] int index = hash(tempWord); ^ dictionary.c:123:1: error: function definition is not allowed here { ^ dictionary.c:138:1: error: function definition is not allowed here { ^ dictionary.c:146:2: error: expected '}' } ^ dictionary.c:73:1: note: to match this '{' {
#include
#include "dictionary.h"
// size of hash table #define SIZE 500000
// create nodes for linked list typedef struct node { char word[LENGTH+1]; struct node* next; } node;
node* hashtable[SIZE] = {NULL};
int hash_it(char* needs_hashing) { unsigned int hash = 0; for (int i=0, n=strlen(needs_hashing); i for (int i = 0; i < strlen(tempWord); i++) { if (tempWord[i] != '\'') tempWord[i] = tolower(tempWord[i]); } // get the hash value of the passed in word int index = hash(tempWord); // go to that index and search for the word struct node* current = hashtable[index]; // if word is found return true while (current != NULL) { if (strcmp(current->word, tempWord) != 0) { current = current->next; } else { return true; } } return false; } // create global variable to count size int dicSize = 0; /** * Loads dictionary into memory. Returns true if successful else false. */ bool load(const char *dictionary) { { // TODO // opens dictionary FILE* file = fopen(dictionary, "r"); if (file == NULL) return false; // create an array for word to be stored in char word[LENGTH+1]; // scan through the file, loading each word into the hash table while (fscanf(file, "%s ", word)!= EOF) { // increment dictionary size dicSize++; // reserve memory for new word node* newWord = malloc(sizeof(node)); // put word in new node strcpy(newWord->word, word); int index = hash(word); if (hashtable[index] == NULL) { hashtable[index] = newWord; newWord->next = NULL; } else { newWord->next = hashtable[index]; hashtable[index] = newWord; } } // close file fclose(file); // return true if successful return true; } /** * Returns number of words in dictionary if loaded else 0 if not yet loaded. */ unsigned int size(void) { if (dicSize > 0) { return dicSize; } // if dictionary hasn't been loaded, return 0 else return 0; } /** * Unloads dictionary from memory. Returns true if successful else false. */ bool unload(void) { // iterate through entire SIZE of the hashtable array for (int i = 0; i < SIZE; i++) { if (hashtable[i] != NULL) DeleteList(&hashtable[i]); } return true; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
