自己写一个函数,将2个字符串连接。(不能用strcat()函数)
自己写一个函数,将2个字符串连接。(不能用strcat()函数)
最佳答案
//函数是以前写的,测试通过,如果有疑问,欢迎交流
//依次输入两个字符串就行
#include<stdio.h>
#define N 100
void cur_stract(char *src, char* tar){
int cur_count = 0;
while(src[cur_count]!='\0'){
cur_count++;
}
int tar_cur_count = 0;
while(tar[tar_cur_count]!='\0'){
src[cur_count] = tar[tar_cur_count];
tar_cur_count++;
cur_count++;
}
src[cur_count] = '\0';
}
int main(){
char a[N], b[N];
gets(a);
gets(b);
cur_stract(a,b);
puts(a);
return 0;
}
其他回答
其它网友回答:
其它网友回答:
#include <stdio.h>
/*
** concatenate t to end of s
** s must be large enough
*/
my_strcat(char *s, char *t) //自定义strcat,加my_防止与系统冲突
{
char *d;
--s;
while(*++s) ;
while(*s++ = *t++) ;
return(d);
}
int main() //测试程序
{
char a[20] = "123456";
char b[] = "7890";
my_strcat(a,b);
printf("%s\n",a);
return 0;
}