1、代码如下:
int MyStrlen(const char *strSrc)
{
assert(strSrc != NULL);
if
(strSrc == NULL)
{
return
0;
}
int i = 0;
while
(*strSrc++ !=
'\0'
)
{
i++;
}
return
i;
}
|
2、VS2010下的原版函数:
/***
*strlen - return the length of a null-terminated string
*
*Purpose:
* Finds the length in bytes of the given string, not including
* the final null character.
*
*Entry:
* const char * str - string whose length is to be computed
*
*Exit:
* length of the string "str", exclusive of the final null byte
*
*Exceptions:
*
*******************************************************************************/
size_t __cdecl strlen (
const char * str
)
{
const char *eos = str;
while( *eos++ ) ;
return( eos - str - 1 );
}
3、另外,可以看看:编写一个标准strcpy函数