现在的位置: 首页 > 综合 > 正文

great strcpy & strlen definition

2012年11月17日 ⁄ 综合 ⁄ 共 395字 ⁄ 字号 评论关闭
//为了实现链式操作,将目的地址返回
char * strcpy( char *strDest, const char *strSrc )  // strSrc is input parameter and should not be changed
{
 assert( (strDest != NULL) && (strSrc != NULL) );// assert parameter
char *address = strDest;  

 while( (*strDest++ = * strSrc++) != ‘\0’ );

  return address;
}


int strlen( const char *str )    //输入参数const
{
     assert( strt != NULL );    //断言字符串地址非0
     int len;

     while( (*str++) != '\0' )
     {  
            len++;
     }

     return len;

}


抱歉!评论已关闭.