您好,关于编程怎么实现strcat函数的功能?

是用C语言做的

HUH函数
浏览 365回答 2
2回答

侃侃尔雅

#include "stdio.h"char* strcat(char s1[],char s2[]){int i,j;for(i=0;s1[i]!=0;i++);for(j=0;s2[j]!=0;i++,j++)s1[i]=s2[j];s1[i]=0;return s1;}int main(){char s1[100]="abc",*s;s=strcat(s1,"def");printf("%s",s);return 0;}

慕桂英4014372

#include <stdio.h>char *strcopy(char *str1,char *str2){&nbsp;char *p = str1;&nbsp;while((*str1)!='\0') str1++;&nbsp; while((*str2)!='\0')&nbsp; {&nbsp; &nbsp;*str1++=*str2++;&nbsp; }&nbsp; *str1='\0';&nbsp; return p;}void main(){&nbsp;char str1[20],str2[10];&nbsp;//开辟大一点的空间&nbsp;printf("str1:\n");&nbsp;gets(str1);&nbsp;printf("str2:\n");&nbsp;gets(str2);&nbsp;printf("连接后:%s\n",strcopy(str1,str2));&nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP