全部博文(534)
分类: C/C++
2007-08-03 15:57:42
#include
函数1
copy_string(char from[],char to[])
{
int i=0;
while (from[i]!='\0') {
to[i]=from[i]; i++;
}
to[i]='\0';
}
函数2
copy_string(char *from,char *to)
{
for (;*from!='\0';from++,to++)
*to=*from;
*to='\0';
}
函数3
copy_string(char *from,char *to)
{
while ((*to=*from)!='\0') {
from++; to++;
}
*to='\0';
}
函数4
copy_string(char *from,char *to)
{
while ((*to++=*from++)!='\0')
*to='\0';
}
函数5
copy_string(char *from,char *to)
{
while (*from!='\0')
*to++=*from++;
*to='\0';
}
函数6
copy_string(char *from,char *to)
{
while (*from) //字符可用ascii代替,\0就是0,*from!=0 与 *from 为真实while执行
*to++=*from++;
*to='\0';
}
函数7
copy_string(char *from,char *to)
{
for (;(*to++=*from++)!=0;)
*to='\0';
}
函数8
copy_string(char *from,char *to)
{
for (;*to++=*from++;)
*to='\0';
}
函数8
copy_string(char from[],char to[])
{
char *p1,*p2;
p1=from;p2=to;
while ((*p2++=*p1++)!='\0')
*to='\0';
}
main()
{
char a[]="i am a teacher.",b[]="i am a student.";
printf("string_a=%s string_b=%s\n",a,b);
copy_string(a,b);
printf("string_a=%s string_b=%s\n",a,b);
}