题目描述
Write code to reverse a C-Style String (C-String means that “abcd” is represented as five characters, including the null character )
写一段代码对字符串进行翻转
char* reverseStr(char *str )
{
if ( str == NULL )
return NULL;
int len = strlen(str);
char *pBegin = str;
char *pEnd = str + len - 1;
while ( pBegin < pEnd )
{
char c = *pBegin;
*pBegin = *pEnd;
*pEnd = c;
++pBegin; --pEnd;
}
return str;
}
代码挺简单的,有没有什么特别需要注意的地方