c语言! 编一程序,将两个字符串连接起来,不要用strcat函数.

c语言! 编一程序,将两个字符串连接起来,不要用strcat函数.最好能写到纸上,这样看得清楚点。

第1个回答  2009-10-29
函数头我就不和你写了!
int a[20],b[20],i=0,j=0;
while(a[i]!='\0')
{
i++;
}
while(b[i]!='\0')
{
a[i++]=b[i++];
}
a[i]='\0';
printf("%s",a);

就可以了!!
第2个回答  2017-04-23
//函数是以前写的,测试通过,如果有疑问,欢迎交流 //依次输入两个字符串就行 #include #define N 一00 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;
第3个回答  2017-04-23
if(q<=n) str3[q]=str1[q] ;

这句有问题,我解释一下你自己改哈。
q=n时,str1[q]='\0';即字符串的结束标志,str3[]的字符到这里就停止了。
第4个回答  2017-04-19
#include<stdio.h>
void mstrcat(char *t,char *s) { while ( *t ) t++; while ( *s ) { *t=*s; t++; s++; } *t=0; }
void main() { char s1[256],s2[256];
scanf("%s%s",s1,s2); mstrcat(s1,s2); printf("%s\n",s1);
}