I'm writing an implementation for Hash Tables in C, but I'm getting bogged down with some stuff. I have written the functions and the data definitions in a separate file.
I have the header file Hashes.h
which looks like:
#ifndef HASHES_H_INCLUDED
#define HASHES_H_INCLUDED
int accumulation(long int);
struct entry_s {
char *key;
char *value;
struct entry_s *next;
};
typedef struct entry_s entry_t;
struct hashtable_s {
int size;
struct entry_s **table;
};
typedef struct hashtable_s hashtable_t;
hashtable_t * ht_create( int );
#endif // HASHES_H_INCLUDED
and I have the Hashes.c
file which looks like:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "Hashes.h"
/*Creates the hashtable*/
hashtable_t *ht_create( int size ) {
hashtable_t * hashtable = NULL;
int i;
if( size < 1 ) return NULL;
/* Allocate the table itself. */
if ( ( hashtable = malloc( sizeof( hashtable_t ) ) ) == NULL ) {
return NULL;
}
/* Allocate pointers to the head nodes. */
if ( ( hashtable->table = malloc( sizeof( entry_t * ) * size ) ) == NULL ) {
return NULL;
}
for( i = 0; i < size; i++ )
{
hashtable->table[i] = NULL;
}
hashtable->size = size;
return hashtable;
}
int accumulation (long int x)
{
int hash = 0;
int i = 0;
while (x != 0)
{
hash += pow(33, i) + x % 10;
x /= 10;
}
return hash;
}
and in the main I have :
#include <stdio.h>
#include <stdlib.h>
#include "Hashes.h"
int main()
{
hashtable_t* myHashTable = ht_create(10000);
return 0;
}
I compiled all the files with no error or warning, but when I run the program I receive the error "Undefined reference to 'ht_create'". If some one has a clue I would deeply appreciate that.
P.S.: I am using CodeBlocks IDE.