模拟实现strncat
代码:
#include<stdio.h>
#include<assert.h>
char* my_strncat(char* dest, const char* src, size_t num) {
assert(dest != NULL && src != NULL);
char* ret = dest;
while (num--) {
*dest++ = *src++;
}
return ret;
}
int main() {
char arr1[20] = "hahaha";
char arr2[10] = "yyyyyy";
my_strncat(arr1,arr2,2);
printf("%s\n", arr1);
return 0;
}
结果: