Background: I created a Hashtable in a file called hash_table.c. Here is part of what my header file hash_table.h contains:
/* hash_table.h */
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
enum {BUCKET_COUNT = 1024};
struct Node {
char *key;
char *value;
struct Node *next;
};
struct Table {
struct Node *array[BUCKET_COUNT];
};
struct Table *TableCreate(void); //creates the table
....
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I want to initiate the Hashtable in a different C file called fdata.c. I don't know what the best way to do this is but here is what I was thinking:
#include "hash_table.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Table *t; //initiate the variable
void testFunc()
{
if(Hashtable does not exist) { //How do I accomplish this? Is it possible?
t = TableCreate(); //create the table
else{
continue...
....
Obviously, if there is a better way to initiate this table I am all ears. (This is my first time using structures with C)
Thanks for the support!