这个程序可以:
#include <stdio.h>
int main()
{void copy_string(char *from, char *to);
char *a="I am a teacher.";
char b[]="you are a student.";
char *t=b;
printf("string a=%s\nstring b=%s\n",a,b);
printf("copy string a to string b:\n");
copy_string(a,t);
printf("\nstring a=%s\nstring b=%s\n",a,b);
return 0;
}
void copy_string(char *from, char *to)
{ for(;*from!='\0';from++,to++)
*to=*from;
*to='\0';
}
改动了几个地方就不行:
#include <stdio.h>
int main()
{void copy_string(char *from, char *to);
char a[]="I am a teacher.";//有改动
char *b="you are a student.";//有改动
char *t=a;//有改动
printf("string a=%s\nstring b=%s\n",a,b);
printf("copy string a to string b:\n");
copy_string(t,b);//有改动
printf("\nstring a=%s\nstring b=%s\n",a,b);
return 0;
}
void copy_string(char *from, char *to)
{ for(;*from!='\0';from++,to++)
*to=*from;
*to='\0';
}
谢谢哥们