自定义个strcpy函数,编程如下:
#include<iostream.h>
#include<iostream.h>
char *strcpy(char *dest,const char *scr);
void main()
{
char *from="asdasdasd";
char *to;
if((to=new char[sizeof(from)+1])==NULL)
{
cout<<"not neough memory.";
exit(1);
}
strcpy(to,from);
cout<<from<<endl
<<to<<endl;
delete[]to;
}
char *strcpy(char *dest,const char *scr)
{
if(scr==NULL)
cout<<"原字符串为空."<<endl;
else
{
while(*scr!='\0')
*(dest++)=*(scr++);
*dest='\0';
}
return dest;
}
那里错了??
[此贴子已经被作者于2007-10-21 12:47:12编辑过]