strcpy函数实现

把字符数组str2中的全部字符拷贝到字符数组str1中(不要使用strcpy函数)

代码如下:

 1 #include <stdio.h>
 2 
 3 //拷贝时注意拷贝完后在s后面加上结束标志'\0' 
 4 char* Strcpy(char *s, char *p)
 5 {    
 6     while(*p)
 7     {
 8         *s = *p;
 9         s++;
10         p++;
11     }
12     *s = '\0';
13 }
14 
15 int main()
16 {
17     char str1[100], str2[100];
18     scanf("%s",&str1);
19     scanf("%s",&str2);
20     Strcpy(str1, str2);
21     printf("%s",str1);
22     
23     return 0;
24 } 

 

posted @ 2017-12-30 16:10  woz333333  阅读(142)  评论(0)    收藏  举报