c - using memcpy to copy a structure -


possible duplicates:
copying 1 structure another
copying 1 structure another

       struct node         {            int n;             struct classifier keys[m-1];            struct node *p[m];         }*root=null; 

i have created newnode of type node

        (*newnode)->keys[i] 

i want copy data keys structure structure clsf_ptr of same type can this,i don't want initialize each member function

       memcpy((*newnode)->keys[i], clsf_ptr)  

for start, should be:

memcpy(&(newnode->keys[i]), &clsf_ptr, sizeof(struct classifier)); 

(assuming newnode pointer-to-node, , clsf_ptr classifier`).

also, struct assignment legal in c, do:

newnode->keys[i] = clsf_ptr; 

note both of these approaches shallow copy. if struct classifier has pointers memory, pointers copied, rather creating new copies of memory.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -