迅雷笔试 字符串反转 C库函数 strrev

char* my_strrev( char* string )
{
 char *left, *right, ch;
 left = right = string;

 while( *right++ != '/0');
 right -= 2;


 while( left<right )
 {
  ch = *left;
  *left = *right;
  *right = ch;
  ++left; --right;
 }

 return string;
}

 

// 测试代码
int _tmain( int argc, TCHAR* argv[] )
{
 char szBuf[10] = {0};
 strcpy_s( szBuf, "hello" );
 printf( "%s", my_strrev(szBuf) );

 system( "pause" );

 return 0;
}

你可能感兴趣的:(c,String,测试,System)