//字符串受限制 strncpy函数 int main() { char arr1[20] = "abcdef"; char arr2[] = "qwer"; strncpy (arr1, arr2, 2); //把arr2的前两个放置在arr1中,指定拷贝多少个字符,基本不会存在放不下 printf("%s\n", arr1);//qwcdef char arr3[20] = "abcdefghi"; char arr4[] = "qwer"; strncpy(arr1, arr2, 6); printf("%s\n", arr1);//qwer,,,实际放的是qwer\0\0ghi,需要f10调试方可看到 return 0;