#include <stdio.h>
#include <stdlib.h>
/*
用指针方式实现strcat.strcat(s,t)将t指向的字符串复制到s指向的字符串尾部
*/
int strcat(char *s,char *t)
{
if( s==NULL)return -1;
while(*s!='/0')
s++;
while( *s++=*t++)
;
return 0;
}
int main(void)
{
char a[1000]={"hello"};
char *b="world";
if( strcat(a,b) !=0)
return -1;
printf("a is :%s",a);
system("pause");
return 0;
}
#include <stdlib.h>
/*
用指针方式实现strcat.strcat(s,t)将t指向的字符串复制到s指向的字符串尾部
*/
int strcat(char *s,char *t)
{
if( s==NULL)return -1;
while(*s!='/0')
s++;
while( *s++=*t++)
;
return 0;
}
int main(void)
{
char a[1000]={"hello"};
char *b="world";
if( strcat(a,b) !=0)
return -1;
printf("a is :%s",a);
system("pause");
return 0;
}
博客展示了一段C语言代码,通过指针方式实现strcat函数,将一个字符串复制到另一个字符串尾部。代码包含函数定义和主函数调用,最后输出拼接后的字符串。

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



