模拟实现strncat

源代码

char* my_strncat(char* dest, char* src, size_t count)
{
 assert(dest != NULL);
 assert(src != NULL);
 char* start = dest;
 while (*dest)
 {
  dest++;
 }
 while (count--)
 {
  *dest++ = *src++;
 }
 *dest = '\0';//将\0存入字符串中
 return start;
}
int main()
{
 char arr1[20] = "hello";
 char arr2[20] = " world";
 my_strncat(arr1, arr2, 4);
 printf("%s\n", arr1);
 return 0;
}

因为记住了地址,所以不用返回值,直接打印就可以.

你可能感兴趣的:(模拟实现strncat)