/*************************************************************************
> File Name: my_strcat.c
> Descripion:my_strcat
> Mail:429423976@qq.com
> Created Time: 2019年08月10日 星期六 01时07分22秒
************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
char* MyStrcat(char *str1, char *str2)
{
int num1 = 0;
int num2 = 0;
char *temp1;
char *temp2;
temp1 = str1;
temp2 = str2;
while(*str1 != '\0') {
num1++;
str1++;
}
while(*str2 != '\0') {
num2++;
str2++;
}
char str[num1 + num2 +1];
str[num1 + num2] = '\0';
int i = 0;
while(*temp1 != '\0') {
str[i] = *temp1;
temp1++;
i++;
}
while(*temp2 != '\0') {
str[i] = *temp2;
temp2++;
i++;
}
return str;
}
int main()
{
char str1[] = "hello";
char str2[] = " world!";
printf("%s\n", MyStrcat(str1, str2));
return 0;
}
strcat函数实现
最新推荐文章于 2023-10-13 17:44:34 发布