background: created hashtable in file called hash_table.c. here part of 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 table ....
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ want initiate hashtable in different c file called fdata.c. don't know best way here thinking:
#include "hash_table.h" #include <stdio.h> #include <stdlib.h> #include <string.h> struct table *t; //initiate variable void testfunc() { if(hashtable not exist) { //how accomplish this? possible? t = tablecreate(); //create table else{ continue... ....
obviously, if there better way initiate table ears. (this first time using structures c)
thanks support!
a global pointer initialized nil
on app startup. can compare against nil
, call tablecreate
.
alternatively, can create table @ startup. (e.g. main
, or if you're writing objective c, application:didfinishlaunchingwithoptions
or along lines.)
Comments
Post a Comment