没 有 我还会问的吗?
追答Strcat函数原型如下:
char *strcat(char *strDest, const char *strSrc) //将源字符串加const,表明其为输入参数
{
char *address = strDest; //该语句若放在assert之后,编译出错
assert((strDest != NULL) && (strSrc != NULL)); //对源地址和目的地址加非0断言
while(*strDest) //是while(*strDest!=’\0’)的简化形式
{ //若使用while(*strDest++),则会出错,因为循环结束后strDest还会执行一次++,那么strDest
strDest++; //将指向'\0'的下一个位置。/所以要在循环体内++;因为要是*strDest最后指
} //向该字符串的结束标志’\0’。
while(*strDest++ = *strSrc++)
{
NULL; //该循环条件内可以用++,
} //此处可以加语句*strDest=’\0’;无必要
return address; //为了实现链式操作,将目的地址返回
}
* C语言标准库函数strcpy的一种典型的工业级的最简实现
* 返回值:
* 返回目标串的地址。
* 对于出现异常的情况ANSI-C99标准并未定义,故由实现者决定返回值,通常为NULL。
* 参数:
* strDestination
* 目标串
* strSource
* 源串
***********************/
char *strcpy(char *strDestination, const char *strSource)
{
assert(strDestination && strSource);
char *strD=strDestination;
while ((*strDestination++=*strSource++)!='\0')
NULL;
return strD;
}