c语言简单实现连接字符串函数

不用string.h实现连接字符串函数

#include
char* connect_str(char* des,const char* src);

int main()
{
    char a[20]="hello";
    char b[20]="world";
    puts(connect_str(a,b));
    //connect_str(a,b);puts(a);
    return 0;
}

char * connect_str(char* des,const char* src)
{
    char *a=des;

    while (*des)
    {
        des++;
    }
    while (*src)
    {
        *des++=*src++;
    }
    *des='\0';//字符串的最后记得加上'\0'
    return a;
}
PS D:\_code_C\coin> .\connect_str.exe
helloworld
PS D:\_code_C\coin>

你可能感兴趣的:(c语言练习,c语言)