//编写一个函数,利用指针将输入的两个字符串s1和s2连接起来,要求短的在前。
//1、使用子函数 char *StrCat(char *s,char *t)2、不能使用字符串函数strcat
#include <stdio.h>
#include <string.h>
char *StrCat(char *s,char *t)
{
int i,j=0;
int h=0;
int sl;
int tl;
sl=strlen(s);
tl=strlen(t);
if( sl>=tl)
{
for(i=tl;i<sl+tl;i++)
t[i]=s[j++];
printf("%s",t);
}
else
{
for(i=sl;i<sl+tl;i++)
s[i]=t[h++];
printf("%s",s);
}
}
int main ()
{
char a[99];
char b[99];
char *s=a;
char *t=b;
gets(a);
gets(b);
*StrCat(s,t);
return 0;
}
编写一个函数,利用指针将输入的两个字符串s1和s2连接起来,要求短的在前
最新推荐文章于 2023-05-09 20:29:28 发布