一、题目?
输入一个字符串,将该字符串从第m个字符开始的全部字符复制成另一个字符串。m有用户输入,值小于字符串的长度。要求编写一个函数mcopy(char *src, char *dst, int m)来完成。
二、代码
1.全部代码如下
#include <stdio.h>
#include <string.h>
void mcopy(char* s1, char* s2, int m);
int main()
{
int n;
char s1[100], s2[100];
while (scanf("%d ", &n) != EOF) {
gets(s1);
mcopy(s1, s2, n);
puts(s2);
}
return 0;
}
void mcopy(char* s1, char* s2, int m) {
int n = 0;
while (n < m - 1) {
s1++;
n++;
}
while (*s1!='\0') {
*s2++ = *s1++;
}
*s2 = '\0';
}
2.测试案例
测试案例如下:
输入:
3 abcdefgh
6 This is a picture.
输出:
cdefgh
is a picture.

本文介绍了一道编程题目,要求编写一个C语言函数`mcopy`,该函数接受一个源字符串`src`、目标字符串`dst`和一个整数`m`作为参数,将源字符串从第`m`个字符开始的内容复制到目标字符串。测试案例展示了输入字符串和输出结果,代码简洁易懂。

1万+

被折叠的 条评论
为什么被折叠?



