#include<iostream.h>
char *strcpy(char *dest,const char *src,int count)
{
char *tmp=dest;
while(count)
{
if((*tmp=*src)!=0) //把src的值复制到dest,如果src的值非空,那么指针自加
src++;
//否则指针不加,src后续都是指向0,及字符串结束,后续的dest值都为0
tmp++;
count--;
}return dest;
}
void main()
{
cout<<&quot;copy src to dest:&quot;<<endl;
char *dest=&quot;agh&quot;;const char *src=&quot;abc&quot;;int count;
//cin>>dest;
//cin>>count;
*strcpy(dest,src,2);
cout<<dest<<endl;
}运行没有任何结果,help,please! |