Skip to content

Instantly share code, notes, and snippets.

@groyoh
Last active May 12, 2016 10:02
Show Gist options
  • Save groyoh/a792fdbf62be1b013fbc477b2a62eead to your computer and use it in GitHub Desktop.
Save groyoh/a792fdbf62be1b013fbc477b2a62eead to your computer and use it in GitHub Desktop.
Memcpy example
/* Taken from http://www.cplusplus.com/reference/cstring/memcpy/ */
#include <stdio.h>
#include <string.h>
typedef struct {
char name[40];
int age;
} Person;
int main ()
{
Person yor = (Person){ .name = "Yohan", .age = 22 };
Person clone;
memcpy ( &clone, &yor, sizeof(yor) );
printf ("Clone: %s, %d \n", clone.name, clone.age );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment