模拟实现strncpy
模拟实现:
#include<stdio.h>
char* my_strncpy(char*dest,char*src,size_t num) {
char* ret = dest;
size_t i = 0;
for (i = 0; i < num; i++) {
*dest = *src;
dest++;
src++;
}
*dest = '\0';
return ret;
}
int main() {
char aim[50] = { 0 };
char src[] = "abcdefg";
my_strncpy(aim,src,3);
printf("%s\n", aim);
return 0;
}