user-0 提问: 求算法给思路(将一个字符串指针中的数据从尾到头倒过来，存到另一个字符串指针中)

回复:
user: user-1
content: 这里的U8应指unsigned char之意，观察变量命名，也无unicode之意，所以忘记中文什么的吧  两个问题： 1、pSrc的长度如何确定？ 2、pTmpSrc还未分配空间。

user: user-2
content: 中文请使用 _wcsrev或_mbsrev   C:\Program Files\Microsoft Visual Studio\VC98\CRT\SRC\MBSREV.C /*** *mbsrev.c - Reverse a string in place (MBCS) * *       Copyright (c) 1985-1997, Microsoft Corporation.  All rights reserved. * *Purpose: *       Reverse a string in place (MBCS) * *******************************************************************************/  #ifdef _MBCS  #include <mtdll.h> #include <cruntime.h> #include <string.h> #include <mbdata.h> #include <mbctype.h> #include <mbstring.h>   /*** * _mbsrev - Reverse a string in place (MBCS) * *Purpose: *       Reverses the order of characters in the string.  The terminating *       null character remains in place.  The order of MBCS characters *       is not changed. * *Entry: *       unsigned char *string = string to reverse * *Exit: *       returns string - now with reversed characters * *Exceptions: * *******************************************************************************/  unsigned char * __cdecl _mbsrev(         unsigned char *string         ) {          unsigned char *start = string;         unsigned char *left  = string;         unsigned char c;          if ( _ISNOTMBCP )                 return _strrev(string);          _mlock(_MB_CP_LOCK);          /* first go through and reverse the bytes in MBCS chars */         while ( *string ) {                  if ( _ISLEADBYTE(*string++) ) {                         if ( *string ) {                                 c = *string;                                 *string = *(string - 1);                                 *(string - 1) = c;                                 string++;                         }                         else /* second byte is EOS */                                 break;                 }         }          /* now reverse the whole string */         string--;         while ( left < string ) {                 c = *left;                 *left++ = *string;                 *string-- = c;         }          _munlock(_MB_CP_LOCK);         return ( start ); }  #endif  /* _MBCS */   C:\Program Files\Microsoft Visual Studio\VC98\CRT\SRC\WCSREV.C /*** *wcsrev.c - reverse a wide-character string in place * *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. * *Purpose: *       defines _wcsrev() - reverse a wchar_t string in place (not including *       L'\0' character) * *******************************************************************************/   #include <cruntime.h> #include <string.h>  /*** *wchar_t *_wcsrev(string) - reverse a wide-character string in place * *Purpose: *       Reverses the order of characters in the string.  The terminating *       null character remains in place (wide-characters). * *Entry: *       wchar_t *string - string to reverse * *Exit: *       returns string - now with reversed characters * *Exceptions: * *******************************************************************************/  wchar_t * __cdecl _wcsrev (         wchar_t * string         ) {         wchar_t *start = string;         wchar_t *left = string;         wchar_t ch;          while (*string++)                 /* find end of string */                 ;         string -= 2;          while (left < string)         {                 ch = *left;                 *left++ = *string;                 *string-- = ch;         }          return(start); }

user: user-3

user: user-3
content: 只能实现英文字符串的翻转 #include <stdio.h>  char* turn_str(char* str_in,char* str_out) { 	char* temp=str_in; 	char* head=str_out; 	while(*str_in)str_in++; 	for(str_in--;str_in>=temp;) 	{ 		*str_out++=*str_in--; 	} 	*str_out='\0'; 	return head; }  int main() { 	char s1[]="this is a book 我的世界"; 	char s2[100]; 	turn_str(s1,s2); 	puts(s2); 	return 0; }  中文会出现乱码

user: user-2
content: 引用 3 楼 nomefat 的回复:2L 的碰到中文就挂了  看楼主U8的意思是有中文吧。。。。。还得先判断一下中英文 然后再复制 _strrev, _wcsrev, _mbsrev Reverse characters of a string.  char *_strrev( char *string );  wchar_t *_wcsrev( wchar_t *string );  unsigned char *_mbsrev( unsigned char *string );  Routine Required Header Compatibility  _strrev <string.h> Win 95, Win NT  _wcsrev <string.h> or <wchar.h> Win 95, Win NT  _mbsrev <mbstring.h> Win 95, Win NT    For additional compatibility information, see Compatibility in the Introduction.  Libraries  LIBC.LIB Single thread static library, retail version  LIBCMT.LIB Multithread static library, retail version  MSVCRT.LIB Import library for MSVCRT.DLL, retail version    Return Value  Each of these functions returns a pointer to the altered string. No return value is reserved to indicate an error.  Parameter  string  Null-terminated string to reverse  Remarks  The _strrev function reverses the order of the characters in string. The terminating null character remains in place. _wcsrev and _mbsrev are wide-character and multibyte-character versions of _strrev. The arguments and return value of _wcsrev are wide-character strings; those of _mbsrev are multibyte-character strings. For _mbsrev, the order of bytes in each multibyte character in string is not changed. These three functions behave identically otherwise.   Generic-Text Routine Mappings  TCHAR.H Routine  _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined  _tcsrev _strrev  _mbsrev  _wcsrev     Example  /* STRREV.C: This program checks an input string to  * see whether it is a palindrome: that is, whether  * it reads the same forward and backward.  */  #include <string.h> #include <stdio.h>  void main( void ) {    char string[100];    int result;     printf( "Input a string and I will tell you if it is a palindrome:\n" );    gets( string );     /* Reverse string and compare (ignore case): */    result = _stricmp( string, _strrev( _strdup( string ) ) );    if( result == 0 )       printf( "The string \"%s\" is a palindrome\n\n", string );    else       printf( "The string \"%s\" is not a palindrome\n\n", string ); }   Output  Input a string and I will tell you if it is a palindrome: Able was I ere I saw Elba The string "Able was I ere I saw Elba" is a palindrome   String Manipulation Routines  See Also   strcpy, _strset

user: user-0
content: 引用 1 楼 zhao4zhong1 的回复:参考C:\Program Files\Microsoft Visual Studio\VC98\CRT\SRC\STRREV.C /*** *strrev.c - reverse a string in place * *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. * *Purpose: *       defines _strrev() - reverse a string in place (not including *       '\0' character) * *******************************************************************************/  #include <cruntime.h> #include <string.h>  /*** *char *_strrev(string) - reverse a string in place * *Purpose: *       Reverses the order of characters in the string.  The terminating *       null character remains in place. * *Entry: *       char *string - string to reverse * *Exit: *       returns string - now with reversed characters * *Exceptions: * *******************************************************************************/  char * __cdecl _strrev (         char * string         ) {         char *start = string;         char *left = string;         char ch;          while (*string++)                 /* find end of string */                 ;         string -= 2;          while (left < string)         {                 ch = *left;                 *left++ = *string;                 *string-- = ch;         }          return(start); }   字符串的内容没有反转.  ( 显示的还是原来的效果.)

user: user-4
content: 2L 的碰到中文就挂了  看楼主U8的意思是有中文吧。。。。。还得先判断一下中英文 然后再复制

user: user-0
content: string 是源字符串指针，start 是反转后的字符串指针,  是这样吗?

user: user-2
content: 参考C:\Program Files\Microsoft Visual Studio\VC98\CRT\SRC\STRREV.C /*** *strrev.c - reverse a string in place * *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved. * *Purpose: *       defines _strrev() - reverse a string in place (not including *       '\0' character) * *******************************************************************************/  #include <cruntime.h> #include <string.h>  /*** *char *_strrev(string) - reverse a string in place * *Purpose: *       Reverses the order of characters in the string.  The terminating *       null character remains in place. * *Entry: *       char *string - string to reverse * *Exit: *       returns string - now with reversed characters * *Exceptions: * *******************************************************************************/  char * __cdecl _strrev (         char * string         ) {         char *start = string;         char *left = string;         char ch;          while (*string++)                 /* find end of string */                 ;         string -= 2;          while (left < string)         {                 ch = *left;                 *left++ = *string;                 *string-- = ch;         }          return(start); }