C examples for string.h:memcpy
<cstring> <string.h>
Copy block of memory
function
void * memcpy ( void * destination, const void * source, size_t num );
Parameter | Description |
---|---|
destination | Pointer to the destination array. |
source | Pointer to the source of data. |
num | Number of bytes to copy. |
destination is returned.
#include <stdio.h> #include <string.h> struct {/*from w w w. ja v a 2s . co m*/ char name[40]; int age; } person, person_copy; int main () { char myname[] = "this is a test."; //copy string memcpy ( person.name, myname, strlen(myname)+1 ); person.age = 46; //copy structure memcpy ( &person_copy, &person, sizeof(person) ); printf ("person_copy: %s, %d \n", person_copy.name, person_copy.age ); return 0; }