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
Post a Comment