2008-01-06

About Strcpy

Realizes Strcpy () Function , Didn't Use C++ Library , Compile With Self .

char * strcpy(char * strdesc,char * strsrc)
{
char *p ;
if(strsrc == NULL)
exit ;
if(strdesc == strsrc)
return strdesc ;
p = strdesc ;
while( *strsrc == '\0')
*strdesc++ = *strsrc++ ;
return p ;
}

In High Quality C / C++ Programming Guide
LinRui's Answer:

char *strcpy(char *strDest, const char *strSrc);
{
assert((strDest!=NULL) && (strSrc !=NULL)); // 2 Points
char *address = strDest; // 2 Points
while( (*strDest++ = * strSrc++) != ‘\0’ ) // 2 Points
NULL ;
return address ; // 2 Points
}

No comments: