程序不能够用strcat()函数和strlen()函数;需要判断输入的m是否超过了str1的长度。本题定义数组:字符串str1为:”Hello word” 字符串str2为:”I like the”。
能不能帮我写一个?
追答#include
void main()
{
char str1[]="hello world";
char str2[]="i like the";
int m,i,j;
printf("输入从第几个字符开始\n");
scanf("%d",&m);
for(i=0;str2[i]!='\0';i++)
{
;
}
for(j=0;str1[j]!='\0';j++)
{
;
}
if(j>m-1)
{
for(int j=m-1;str1[j]!='\0';j++,i++)
{
str2[i] = str1[j];
}
str2[i] = '\0';
printf("%s",str2);
}
else
{
printf("没有第%d个字符\n",m);
}
return ;
}
能不能帮我写一个?
追答#include
void main()
{
char str1[]="hello world";
char str2[]="i like the";
int m,i,j;
printf("输入从第几个字符开始\n");
scanf("%d",&m);
for(i=0;str2[i]!='\0';i++)
{
;
}
for(j=0;str1[j]!='\0';j++)
{
;
}
if(j>m-1)
{
for(int j=m-1;str1[j]!='\0';j++,i++)
{
str2[i] = str1[j];
}
str2[i] = '\0';
printf("%s",str2);
}
else
{
printf("没有第%d个字符\n",m);
}
return ;
}