reading the book of 《the C programing language》,write a program by myself about strcat ,but here is a mistake. I recode the program here in order to find the causation in future.
#include <stdio.h>
void myStrcat(char s[],char t[])
{
int i=0,j=0;
while(s[i] != '\0') i++;
while((s[i++]=t[j++]) != '\0');
}
int main()
{
char s[]="abde";
char t[]="word!";
myStrcat(s,t);
printf("%s\n",s);
}
I guess the problem is the memory of allocation.
本文分享了一个关于C语言中字符串连接函数strcat的手写实现,并记录了在实现过程中遇到的问题及可能的原因。作者尝试自己编写一个strcat函数,但在运行时出现了错误,疑似与内存分配有关。
2166

被折叠的 条评论
为什么被折叠?



