急求此题答案 急急急

来源:百度知道 编辑:UC知道 时间:2024/05/25 04:24:39
写一个函数int mystrcat(char *t,char *s),其功能是将字符串s中的所有小写字母连接到字符串t上。要求:在主函数中声明字符数组s和t并初始化,首先输出原始串t的内容,调用mystrcat后由main函数输出t的内容。本题不许使用字符串处理函数。

我给你做,等会。
mystrcat怎么返回int?没弄错?用c++可以?

还有,你的输出是再传回t 非要是t还是重新只要满足条件的输出就可以?

已经编译运行通过:
#include <conio.h>
#include <stdio.h>

#define N 20 //这个是s的最大长度,可以自己改
#define M 40 //这个是t的最大长度,可以自己改

int mystrcat(char *t,char *s)
{
int i=0,num=0,j=0;
for(;*(t+num)!='\0';) num++;

for(i=num;(i<M)&&((i-num)<N);i++)
{
if((*(s+i-num)>='a')&&(*(s+i-num)<='z'))
{
*(t+num+j)=*(s+i-num);
j++;
}
}
return 1;
}

void main()
{
char t[M]={NULL},s[N]={NULL};

printf("请输入字符串t: \n");
gets(t);

printf("请输入字符串s: \n");
gets(s);

printf("输入的字符串t为:\n%s\n",t);

mystrcat(t,s);

printf("处理后的字符串t为:\n%s\n",t);

getch();
}