strcat的实施

编程入门 行业动态 更新时间:2024-10-28 17:23:55
本文介绍了strcat的实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试自己实现的strcat,我发现从维基中的strcat的实施像这个......但是当我使用它,有段错误。

这有什么错低于code?

的char *strcat的(字符* DEST,为const char * SRC){    为size_t I,J;    对于(i = 0; DEST [I] ='\\ 0';!我++)        ;    为(J = 0; SRC [J] ='\\ 0';!J ++)        DEST [I + J] = SRC [J]。    DEST [I + J] ='\\ 0';    返回DEST;}

解决方案

在code是好的。

看起来你必须在调用code的一个问题。

你记得为目标字符串分配足够的内存?

I tried to implement the strcat by myself, and I found the strcat implementation from Wiki like this......but when I use it, there is segmentation fault.

What's wrong with the code below?

char * strcat(char *dest, const char *src) { size_t i,j; for (i = 0; dest[i] != '\0'; i++) ; for (j = 0; src[j] != '\0'; j++) dest[i+j] = src[j]; dest[i+j] = '\0'; return dest; }

解决方案

the code is okay.

Looks like you have a problem in the calling code.

Did you remember to allocate enough memory for the target string?

更多推荐

strcat的实施

本文发布于:2023-07-29 06:38:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1238168.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:strcat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!