编写一个函数 char *mystrcpy(char *s1, const char *s2)
它的功能是把字符串s2中的所有字符复制到字符数组s1中。函数返回指向数组s1第一个元素的指针。
函数接口定义:
char *mystrcpy(char *s1, const char *s2)
其中 s1
和 s2
都是用户传入的参数。 函数把字符串s2
中的所有字符复制到字符数组s1
中。函数返回指向数组s1第一个元素的指针。
裁判测试程序样例:
#include <stdio.h>
char *mystrcpy(char *s1, const char *s2);
int main(void)
{
char str1[30], str2[30], str3[30];
gets(str3);
mystrcpy(str1, mystrcpy(str2, str3));
printf("str1: %s\n", str1);
printf("str2: %s\n", str2);
printf("str3: %s\n", str3);
return 0;
}
/* 请在这里填写答案 */
输入样例:
在这里给出一组输入。例如:
Hello world!
输出样例:
在这里给出相应的输出。例如:
str1: Hello world!
str2: Hello world!
str3: Hello world!
C程序如下:
char *mystrcpy(char *s1, const char *s2)
{
char* a=s1;
while(*s2!='\0')
{
*s1=*s2;
s1++;
s2++;
}
*s1='\0';
return a;
}