C语⾔⾃定义字符串拼接函数#include "stdio.h"
//函数原型
char *cat(char *a,char *b);
void main(){
char a[100],b[100];
gets(a);//输⼊字符串a
自定义函数怎么用c语言
gets(b);//输⼊字符串b
cat(a,b);//拼接a,b字符串
puts(a);
}
char *cat(char *a,char *b){
/
/先求出⽬标数组的长度,在长度之后进⾏拼接
int i = 0;
while(*(a+i)!='\0'){
++i;
}
int j = 0;
while(*(b+j)!='\0'){
*(a+i+j) = *(b+j);
++j;
}
*(a+i+j) = '\0';//如果不加这⼀句会出现很多烫烫烫
return a;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。