int main(int argc, char* argv[]){ Hashtable* table = HTCreate(10, hashfct, freefct, cmpfct); int* ptr = NULL; int i = 0; for(i = 0; i < 5; i++){ ptr = malloc(sizeof(int)); *ptr = i; HTAdd(table, ptr, ptr); } for(i = 0; i < 5; i++){ ptr = malloc(sizeof(int)); *ptr = i; int* v = HTGet(table, ptr); printf("%d\n",*ptr); free(ptr); free(v); } HTDestroy(table); return 0; }
/* * DictionaryAdd * * Author: Christian Schafmeister (1991) * * Add an entry to the DICTIONARY. */ void DictionaryAdd( DICTIONARY dDict, char *sKey, GENP PData ) { int iLen; char *cPKey; zDictionarySortCleanup(dDict); /* Allocate memory for the key */ iLen = strlen(sKey); MALLOC( cPKey, char*, iLen+1 ); strcpy( cPKey, sKey ); HTAdd( dDict->htEntries, cPKey, PData ); }