Wednesday 12 June 2019

Using malloc in C to allocate space for a typedef'd type

I'm not sure exactly what I need to use as an argument to malloc to allocate space in the table_allocate(int) function. I was thinking just count_table* cTable = malloc(sizeof(count_table*)) , but that doesnt do anything with the size parameter. Am i supposed to allocate space for the list_node_t also? Below is what I am working with.



in the .h file I'm given this signature:





//create a count table struct and allocate space for it
//return it as a pointer
count_table_t* table_allocate(int);



Here are the structs that I'm supposed to use:





typedef struct list_node list_node_t;

struct list_node {
char *key;
int value;

//the next node in the list
list_node_t *next;
};


typedef struct count_table count_table_t;

struct count_table {
int size;
//an array of list_node pointers
list_node_t **list_array;
};




Thanks!

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...