let us say i have a node as follows..
struct hnode
{
char* data;
struct hnode* hlink;
struct vnode* vlink;
};
which malloc statement should i use in the following gethnode function which returns the address of a hnode... char* data has to be the string that has to be copied to char* data in hnode...
struct hnode* gethnode(char* hdata)
{
struct hnode *x;
x=(struct hnode *)malloc(sizeof(struct hnode)+strlen(hdata));
/*should i use the malloc statement mentioned above
or should i use malloc(sizeof(struct hnode)); the one without strlen(data) */
struct hnode needs the size of 3 pointers, char* + struct hnode* + struct vnode* and you don't have to worry about what these pointer's point to while allocating memory for hnode*.
struct hnode needs the size of 3 pointers, char* + struct hnode* + struct vnode* and you don't have to worry about what these pointer's point to while allocating memory for hnode*.