题目描述
利用指针完成字符串复制函数void strcpy(char* s1, char* s2)。
输入
输入包括两行,分别为字符串s1和s2。
输出
将s1赋值为s2后,分别输出s1和s2。
代码:
#include<stdio.h>
void strcpy(char *p1,char *p2);
int main(void)
{
char a[100];
char b[100];
gets(a);
gets(b);
strcpy(a,b);
puts(a);
puts(b);
return 0;
}
void strcpy(char *p1,char *p2)
{
while(*p2!='\0')
{
*p2=*p1;
p1++;
p2++;
}
}