学习目标:
#include <stdio.h>
#include <string.h>
int main()
{
char str1[] = "Sample string";
char str2[40];
char str3[40];
strcpy(str2, str1);
strcpy(str3, "copy successful");
printf("str1: %s\n str2: %s\n str3: %s\n", str1, str2, str3);
return 0;
}
学习产出:
将源指向的C字符串复制到目标指向的数组中,包括终止空字符(并在此点停止)。
为了避免溢出,destination指向的数组的大小应该足够长,以包含与source相同的C字符串(包括结束的null字符),并且不应该在内存中与source重叠。