c8-20-3.c 643 B

123456789101112131415161718
  1. #include <stdio.h>
  2. int main()
  3. {void copy_string(char *from, char *to);
  4. char *a="I am a teacher.";
  5. char b[]="You are a student.";
  6. char *p=b; // 使指针变量p指向b数组首元素
  7. printf("string a=%s\nstring b=%s\n",a,b); // 输出a串和b串
  8. printf("\ncopy string a to string b:\n");
  9. copy_string(a,p); // 调用copy_string函数,实现复制
  10. printf("string a=%s\nstring b=%s\n",a,b);
  11. return 0;
  12. }
  13. void copy_string(char *from, char *to) // 定义函数,形参为字符指针变量
  14. { for(;*from!='\0';from++,to++)
  15. {*to=*from;}
  16. *to='\0';
  17. }