#include <stdio.h>
#include <stdlib.h>
char* strcat_self(char *strFrist,char *strSecond){
int i=0,j=0;
static char newstr[20];
char *p;
p = newstr;
while(*(strFrist+i)!='\0'){
*(p+i) = *(strFrist+i);
i++;
}
while(*(strSecond+j)!='\0'){
*(p+i) = *(strSecond+j);
i++;
j++;
}
return newstr;
}
int main() {
char str1[20],str2[20],*newstr;
printf("请输入第一个字符串:\n");
gets(str1);
printf("请输入第二个字符串:\n");
gets(str2);
newstr = strcat_self(str1,str2);
printf("字符串1:%s 字符串2:%s 连接后:%s\n",str1,str2,newstr);
system("pause");
return EXIT_SUCCESS;
}
【C语言】自定义连接两个字符串函数
最新推荐文章于 2022-09-16 17:07:44 发布