关于函数strcat的问题

Posted dsfsf

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于函数strcat的问题相关的知识,希望对你有一定的参考价值。

自己写了一个用以连接两个字符串的函数strcat
但是打印出来有乱码,是不是哪里不对?
代码如下:
char *strcat(char *s, char *t) {
    char *q = s;
    while (*t != ‘\0‘) {
        while (*s != ‘\0‘) 
            s++;
        *s++ = *t++;
    }
    return q;
}
int main()
{
    char s[] = "abc";
    char t[] = "123";
    printf("%s\n", strcat(s, t));
    return 0;
}

http://shijue.me/community/photo-details/d482931ec8fa4921b3b9888eb5936f2d_d
http://shijue.me/community/photo-details/443ca2545729439c9dcb9bc11b52c7b6_d
http://shijue.me/community/photo-details/2815e5f27aa64bf799ba70ee18d3afcf_d
http://shijue.me/community/photo-details/ffbef846a0cd4e9894fd73900ca0f90c_d
http://shijue.me/community/photo-details/19e2b76e876b4b2a81aa780f89792c71_d
http://shijue.me/community/photo-details/59aedcd1cf6d4592b3352c976171a19e_d
http://shijue.me/community/photo-details/6f83a9d7df2643feb5192c342bab7003_d
http://shijue.me/community/photo-details/3fb04ea755cb42a08da930756274e993_d
http://shijue.me/community/photo-details/96718ba3da1b489284a1175b1023bc3c_d
http://shijue.me/community/photo-details/e37e1ebfde16493baaead6bf14fc8ade_d
http://shijue.me/community/photo-details/896e03198791409e978f5ecedd093bcc_d
http://shijue.me/community/photo-details/401984c46f7a4b2d8f7854f58c2e15a2_d
http://shijue.me/community/photo-details/1619862c64c6455db54c224d1a8b9b99_d
http://shijue.me/community/photo-details/b0bc415f556c4c43bfaeb3d339665b69_d
http://shijue.me/community/photo-details/7237d93720244c8bad75434020457f6f_d
http://shijue.me/community/photo-details/3808fd894b6e4139a647dc7032f2bb4d_d
http://shijue.me/community/photo-details/d31c343aa8f14e0684cc97cec228b5c6_d
http://shijue.me/community/photo-details/4d9c44e25c7648a29f789765ccd2e0cd_d
http://shijue.me/community/photo-details/92ab16a0e2fc49078b5d736137347838_d
http://shijue.me/community/photo-details/9ef59bcb8bc143efbede448a18c95046_d
http://shijue.me/community/photo-details/83bdeb5d011f4f709960817c173aa128_d
http://shijue.me/community/photo-details/29bd553d5e48442f97fefde7b6499157_d
http://shijue.me/community/photo-details/fb845a512d3b4581b206f3132c8afa01_d
http://shijue.me/community/photo-details/ebfb882be4ee4abcbaaec876955e0883_d
http://shijue.me/community/photo-details/f2070ab6895c4b838c97b44a726faad8_d
http://shijue.me/community/photo-details/3a15d6bb9c3c44caaebfba50c76dd41a_d
http://shijue.me/community/photo-details/5f44fdd2f4f941db96e6d01081a50911_d
http://shijue.me/community/photo-details/c5ec9856ee074c33ab0fbb7064a352ed_d
http://shijue.me/community/photo-details/7a2dee02e8d5477fab6644552e4f6142_d
http://shijue.me/community/photo-details/689da3673b1a4f85b294f5e90bd7a3ae_d
http://shijue.me/community/photo-details/1a4ea5578dc94b95a9874c0158088ab3_d
http://shijue.me/community/photo-details/bf3a31a60f9b4ccc915b91fdbacb7d0b_d

http://shijue.me/community/photo-details/51447882662d4b77b338bcc719e94a95_d
http://shijue.me/community/photo-details/f69ab93bb162402992bd3ab824cb2101_d
http://shijue.me/community/photo-details/93bac6ecab8b4ea09cdcc15113c496b4_d
http://shijue.me/community/photo-details/dff15a6d87614c04b7aba7232e7b7c2b_d
http://shijue.me/community/photo-details/19898bd6f6ba449e8cde0fde61a11994_d
http://shijue.me/community/photo-details/ba9a320d8dbc4a66ae1017a94cada54a_d
http://shijue.me/community/photo-details/1994aa5c90c649c19cb453dc040b709d_d
http://shijue.me/community/photo-details/b7660ea640da46c3918692d54ce7080b_d
http://shijue.me/community/photo-details/fbdd96dc0617407da714c0014b80882f_d
http://shijue.me/community/photo-details/578f7458705c4fefbf925047f9cf8b42_d
http://shijue.me/community/photo-details/fe8ededd8082466cad99e8e36d5d2f6c_d
http://shijue.me/community/photo-details/c1e6d8d8bda24fdf924942f3bf703771_d
http://shijue.me/community/photo-details/39189d8d51c345089828566808c631ac_d

以上是关于关于函数strcat的问题的主要内容,如果未能解决你的问题,请参考以下文章

C语言中如何不用strcat函数来连接2个数组

strcat函数如何执行

零基础学C语言带你解析字符串连接函数:strcat_s 函数

C语言strcat函数怎么用

strcat函数越界的问题

编一个程序,将两个字符串连接起来,(1)用strcat函数(2)不用strcat函数。