school

thing1's amazing school repo
Log | Files | Refs | Submodules | README

dict.c (438B)


      1 #include <stdlib.h>
      2 #include <string.h>
      3 
      4 typedef struct dict_t {
      5 	int id;
      6 	void *data;
      7 }dict_t;
      8 
      9 dict_t *dictalloc(){
     10 	dict_t *output = malloc(sizeof(dict_t));
     11 	return output;
     12 }
     13 
     14 int dictset(dict_t *dict, int id, void *data){
     15 	dict->id = id;
     16 	
     17 	dict->data = malloc(sizeof(data));
     18 	if (dict->data == NULL)
     19 		return 1;
     20 	memcpy(dict->data, data, sizeof(data));
     21 	
     22 	return 0;
     23 }
     24 
     25 void dictfree(dict_t *dict){
     26 	free(dict->data);
     27 	free(dict);
     28 }
     29