#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void my_strcat(char *str1, char *str2)
{
//判断字符是否为空
if (str1 == NULL || str2 == NULL)
{
printf("str1 == NULL || str2 == NULL");
return;
}
//到str1的末尾
while (*str1)
str1++;
//把字符串str2拷贝到字符串str1的末尾
while (*str2)
{
*str1++ = *str2++;
}
*str1 = '\0';//字符串str1末尾添加'\0'
}
int main()
{
char str1[100] = "hello world";
char str2[100] = " hello silence";
my_strcat(str1, str2);
printf("%s\n", str1);
return EXIT_SUCCESS;
}
#include <string.h>
#include <stdlib.h>
void my_strcat(char *str1, char *str2)
{
//判断字符是否为空
if (str1 == NULL || str2 == NULL)
{
printf("str1 == NULL || str2 == NULL");
return;
}
//到str1的末尾
while (*str1)
str1++;
//把字符串str2拷贝到字符串str1的末尾
while (*str2)
{
*str1++ = *str2++;
}
*str1 = '\0';//字符串str1末尾添加'\0'
}
int main()
{
char str1[100] = "hello world";
char str2[100] = " hello silence";
my_strcat(str1, str2);
printf("%s\n", str1);
return EXIT_SUCCESS;
}