69,371
社区成员
发帖
与我相关
我的任务
分享
void copy_string(char from[],char to[])
{
int i=0;
while(from[i]!='\0')
{
to[i]=from[i];
i++;
}
to[i]='\0';
}
void main()
{
char a[]="I am a teacher.";//运行无错误程序
char b[]="You are a student.";//运行无错误程序
char *a="I am a teacher.";//运行出错程序
char *b="You are a student.";//运行出错程序
printf("string a=%s\nstring b=%s\n",a,b);
copy_string(a,b);
printf("string a=%s\nstring b=%s\n",a,b);
}
char *a="I am a teacher.";//运行出错程序
char *b="You are a student.";//运行出错程序 //指向字符串常量的指针不能被修改内容导致报错
char *a="I am a teacher.";//运行出错程序
char *b="You are a student.";//运行出错程序