#include <stdio.h> #include <stdlib.h> #include <assert.h> char *my_strncpy(char *dest,const char *src, int len) { char *ret = dest; while (len--) { *dest++ = *src++; } *dest = ‘\0‘; return ret; } int main() { char arr1[20] = "hello "; char arr2[20] = "world!"; char *ret = my_strncpy(arr1, arr2, 1); printf("%s", ret); system("pause"); return 0; }
时间: 2024-08-11 03:27:30