【C语言】自定义连接两个字符串函数

来源:互联网 发布:金融时间序列数据 编辑:程序博客网 时间:2024/05/04 17:37
#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;}
0 0
原创粉丝点击