请编写一个自定义函数mystrcat,该函数要完成库函数strcat的功能,请编写main函数
1个回答
展开全部
#include <stdio.h>
char *mystrcat(char *s1, char *s2)
{
char *p = s1;
char *q = s2;
while (*p != '\0') p++;
while (*q != '\0') *p++ = *q++;
*p = '\0';
return s1;
}
int main()
{
char a[100] = "hello";
char *b = " baidu";
printf("%s\n", mystrcat(a, b)); // 运行结果为hello baidu
return 0;
}
char *mystrcat(char *s1, char *s2)
{
char *p = s1;
char *q = s2;
while (*p != '\0') p++;
while (*q != '\0') *p++ = *q++;
*p = '\0';
return s1;
}
int main()
{
char a[100] = "hello";
char *b = " baidu";
printf("%s\n", mystrcat(a, b)); // 运行结果为hello baidu
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询