void reverseLHC( char *str )
{
char* end = str;
char tmp;
if (str)
{
while(*end)
{ //找出字符串末尾
++end;
}
--end; //回退一个字符,最后一个为null字符
//从字符串首尾开始交互两个字符,直至两个指针在中间碰头
while(str < end)
{
tmp = *str;
*str++ = *end;
*end-- = tmp;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
char str[] = "abcd";
cout << "str : " << str << endl;
reverseLHC(str);
cout << "Reverse str : " << str << endl;
system("pause");
return 0;
}