#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 *p=b;
printf("a=%s\nb=%s\n",a,b);
printf("\ncopy string a to string b:\n");
copy_string(a,p);
printf("a=%s\nb=%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.";
printf("a=%s\nb=%s\n",a,b);
printf("\ncopy string a to string b:\n");
copy_string(a,b);
printf("a=%s\nb=%s\n",a,b);
return 0;
}
void copy_string(char *from, char *to)
{ for(;*from!='\0';from++,to++)
{
*to=*from;
}
*to='\0';
}
char *b="You are a student.";
这样b就是一个常量字符串了,大小为strlen(b);是不可以给常量赋值的