C语言小问题,急求,100分当时送,能用,追加100

来源:百度知道 编辑:UC知道 时间:2024/05/14 17:28:55
编写一个函数名为link函数,不允许调用字符串函数,要求如下:

(1) 形式参数:s1[40],s2[40],s3[80]存放字符串的字符型数组名。

(2) 功能:将s2连接到s1后存入s3中。

(3) 返回值:连接后字符串的长度。

编写一个C程序,输入两个字符串s1和s2,调用link函数,将s1连接到s2后存入s3中,输出s3的内容及长度
一楼少一个输出又多少个字符

#include <stdio.h>

int link(char s1[40], char s2[40], char s3[80])
{
int i = 0, j = 0;

for (;; i++)
{
if (!s1[i])
{
break;
}

s3[i] = s1[i];
}

for (;; j++)
{
s3[i + j] = s2[j];

if (!s2[j])
{
break;
}
}

return i + j;
}

void main()
{
char s1[40], s2[40], s3[80];
int l;

gets(s1);
gets(s2);

l = link(s1, s2, s3);

printf("%s, %d\n", s3, l);
}

int link(char* s1, char* s2, char* s3)
{
int count = 0;
int temp = 0;
s3 = s1;
while(*s1++ != 0)
count++;
while(*s1++ = *s2++ && *s2++ != 0)
count++;
return count;

}

int link(str *s1,str *s2,str *s3){
for(;*s1!='\0';s1++)
{ *s3=*s1;
s3++;
}
for(;*s