当把char* to ="You are a student."换成:char a[]="You are a student.";char *to=a;没问题。编译,连接没问题,但运行就出问题了。调试显示:"unhandled exception in Test01025.exe:0xC000005:Access Violation."请问这是什么原因?
#include<stdio.h>
int main()
{
void copy_string(char *from,char *to);
char *from="I am a teacher.";
char *to="You are a student.";//当把这一行换成:char a[]="You are a student.";char *to=a;没有问题
printf("string a=%s\nstring b=%s\n",from,to);
printf("copy string a to string b:\n");
copy_string(from,to);
printf("\nstring a=%s\nstring b=%s\n",from,to);
return 0;
}
void copy_string(char *from,char *to)
{
while(*to=*from)
{to++;
from++;
}
}
qq_追梦_26
相关分类