一个简单的c语言程序。帮看下为什么VC6.0编译能通过,运行却出错。
#include<stdio.h>voidmain(){voidcopy_string(char*from,char*to);char*a="Iamateacher";c...
#include<stdio.h>
void main()
{
void copy_string(char *from,char *to);
char *a="I am a teacher";
char *b="You are a student";
copy_string(a,b);
printf("a is %s\nb is %s\n",a,b);
}
void copy_string(char *from,char *to)
{
while(*from!='\0')
{
*to=*from;
from++;
to++;
}
*to='\0';
} 展开
void main()
{
void copy_string(char *from,char *to);
char *a="I am a teacher";
char *b="You are a student";
copy_string(a,b);
printf("a is %s\nb is %s\n",a,b);
}
void copy_string(char *from,char *to)
{
while(*from!='\0')
{
*to=*from;
from++;
to++;
}
*to='\0';
} 展开
3个回答
展开全部
char *a="I am a teacher";
正确写法应为:const char *a="I am a teacher";
因为a指向一个常量字敏老符串
所以不能在copy_string函数中修改a所指向的内存空间的内容。
char *b同理
修改:
#include<stdio.h>
void main()
{
void copy_string(char *from,char *to);
char a[]="I am a teacher"; //盯明修改
char b[]="You are a student";/凯拿告/修改
copy_string(a,b);
printf("a is %s\nb is %s\n",a,b);
}
void copy_string(char *from,char *to)
{
while(*from!='\0')
{
*to=*from;
from++;
to++;
}
*to='\0';
}
正确写法应为:const char *a="I am a teacher";
因为a指向一个常量字敏老符串
所以不能在copy_string函数中修改a所指向的内存空间的内容。
char *b同理
修改:
#include<stdio.h>
void main()
{
void copy_string(char *from,char *to);
char a[]="I am a teacher"; //盯明修改
char b[]="You are a student";/凯拿告/修改
copy_string(a,b);
printf("a is %s\nb is %s\n",a,b);
}
void copy_string(char *from,char *to)
{
while(*from!='\0')
{
*to=*from;
from++;
to++;
}
*to='\0';
}
展开全部
我这扮搜仔运行成厅汪功
#include<stdio.h>漏基
void copy_string(char *from,char *to);
int main()
{
char *a="I am a teacher";
char *b="You are a student";
copy_string(a,b);
printf("a is %s\nb is %s\n",a,b);
}
void copy_string(char *from,char *to)
{
while(*from!='\0')
{
*to=*from;
from++;
to++;
}
*to='\0';
}
#include<stdio.h>漏基
void copy_string(char *from,char *to);
int main()
{
char *a="I am a teacher";
char *b="You are a student";
copy_string(a,b);
printf("a is %s\nb is %s\n",a,b);
}
void copy_string(char *from,char *to)
{
while(*from!='\0')
{
*to=*from;
from++;
to++;
}
*to='\0';
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>巧做明
char* copy_string(char *from,char *to);
void main()
{
char a[]="I am a teacher";
char b[]="You are a student"孝告;
copy_string(a,b);
printf("a is %s\nb is %s\n",a,b);
}
char* copy_string(char *from, char *to)
{
char* address= to;
while(*from != '\0')
{
*to = *from;
from++;
to++;
}
*to='\0';
return address;
}
楼主就是写个字符串拷贝函数然后调用胡毁
我改了下 楼主看看 可以正常拷贝
char* copy_string(char *from,char *to);
void main()
{
char a[]="I am a teacher";
char b[]="You are a student"孝告;
copy_string(a,b);
printf("a is %s\nb is %s\n",a,b);
}
char* copy_string(char *from, char *to)
{
char* address= to;
while(*from != '\0')
{
*to = *from;
from++;
to++;
}
*to='\0';
return address;
}
楼主就是写个字符串拷贝函数然后调用胡毁
我改了下 楼主看看 可以正常拷贝
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询