C/Memory/Memory Copy
Copy bytes to buffer from buffer: how to use memcpy
<source lang="cpp">
- include <stdio.h>
- include <string.h>
int main () {
char str1[]="This is a line."; char str2[40]; char str3[40]; memcpy (str2, str1, strlen(str1) + 1); memcpy (str3, "copy successful", 16); printf ("str1= %s\n str2= %s\n str3= %s\n", str1, str2, str3); return 0;
}
</source>
Memory copy
<source lang="cpp">
- include <stdio.h>
- include <string.h>
- define SIZE 80
int main(void) {
char buf1[SIZE], buf2[SIZE]; strcpy(buf1, "Hiiiiiiiiiiiiiiiiiiii..."); memcpy(buf2, buf1, SIZE); printf(buf2); return 0;
}
</source>