I'm still having trouble understanding how to copy structs that include char* fields\other struct fields:
typedef struct node{
int id;
struct node* parent
char * nodeName;
struct node* nodes[100];
}NODE,*pNODE;
I want to use this function : pNODE copyNode(pNODE oldNode)
1. i know that first I should do allocation for the new pointer data , and do the followong:
pNODE newNode = (pNODE)calloc(1,sizeof(NODE));
newNode.id=oldNode.id
//for the string that I want to copy I should allocate and use strcpy - in order not to point at the same string
but now I'm lost regarding the parent node, how do I copy it ? if I just do : newNode.parent=oldNode.parent
I point at the same parent object, and if I change it's Id for example - it will change both the id of newNode and oldNode. how can I copy it?? without pointing at the same one?
and how can i copy the pointer array??
thank you!