1 #include<stdio.h> 2 #include<assert.h> 3 #include<string.h> 4 5 #define N 20 6 char *my_strcpy(char *dest, char *src) 7 { 8 assert((dest != NULL)&&(src != NULL));//断言:判断表达式一定为真,若为假,则终止程序 9 char *p = dest; 10 while(*dest = *src) 11 { 12 if(*src == '\0') 13 break; 14 dest++; 15 src++; 16 } 17 return p; 18 } 19 20 int main(int argc, const char *argv[]) 21 { 22 char buf[N] = {"abcdefgtyui"};//定义需要传给形参,给形参赋值的变量 23 char buff[] = {"12345"}; 24 char *p = NULL; 25 int i = 0; 26 p = my_strcpy(buf, buff); 27 for(i = 0;i< N;i++) 28 { 29 //printf("%c ",*(p + i)); 30 printf("%c ",p[i]); 31 } 32 printf("strcpy(buf, buff) = %s\n", p); 33 p = strcpy(buf, buff); 34 printf("strcpy(buf, buff) = %s\n", p); 35 36 putchar('\n'); 37 return 0; 38 }