输入一个正整数 repeat (0<repeat<10),做 repeat 次下列运算:
输入一个字符串 t 和一个正整数 m,将字符串 t 中从第 m 个字符开始的全部字符复制到字符串 s 中,再输出字符串 s。
要求定义并调用函数 strmcpy(s,t,m), 它的功能是将字符串 t 中从第 m 个字符开始的全部字符复制到字符串 s 中,函数形参s和t的类型是字符指针,形参m的类型是int,函数类型是void。
输入输出示例:括号内为说明,无需输入输出
输入样例:
3 (repeat=3)
happy new year
7
happy
1
new
4
输出样例:
new year (从"happy new year"第7个字符开始组成的新字符串为"new year")
happy (从"happy"第1个字符开始组成的新字符串为"happy")
error input ("new"的长度小于4)
void strmcpy(char *s,char *t,int m)
{
s=t+m-1;
}
#include<string.h>
#include<stdio.h>
int main()
{
int m,i,repeat;
scanf("%d",&repeat);
getchar();
for( i=0;i<repeat;i++)
{
char ch[1000]={0},th;
gets(ch);
scanf("%d",&m);
getchar();
char *s=&th,*t=ch;
if(strlen(ch)>m)
{
strmcpy(s,t,m);
printf("%s\n",s);
}
else
printf("error input\n");
}
return 0;
}