字符串逆序

 char * StrReverse(char * ch)
{
 char tempch,* tch;
 int Len,i;
 tch = ch;
 printf("/n");
 Len = strlen(ch);
 printf("Len = %d/n",Len);
 for(i=0;i<Len/2;i++)
 {
  tempch = *tch;
  *tch = *(tch + Len - 2*i - 1);
  *(tch+Len-2*i-1) = tempch;
  tch++;
 }
 return ch;
}
main()
{
 puts(StrReverse("123456"));
 system("pause");
}

下面是MS的C库给出的代码:

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);
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ammana_babi/archive/2006/07/18/937871.aspx

你可能感兴趣的:(字符串逆序)