#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
char* Reverse(char* s)
{
//将q指向字符串最后一个字符
char* q = s ;
while( *q++ ) ;
q -= 2 ;
//分配空间,存储逆序后的字符串。
char* p = (char *)malloc(sizeof(char) * (q - s + 2)) ;
char* r = p ; // 逆序存储
while(q >= s)
*p++ = *q-- ;
*p = ‘\0‘ ;
return r ;
}
int main(void)
{
char a[10] ="hello";
char *q = NULL;
q =Reverse(a);
printf("%s\n",q);
return 0;
}
字符串逆序(使用指针实现)
原文:http://www.cnblogs.com/wqh2965031/p/3990940.html