代码如下:
//==================================
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
void main()
{
char p[] = "don't cry for me argentina!";
char c ;
char *p1 = p;
char *p2 = p + strlen(p) -1;
while (p1 < p2)
{
c = *p1;
*p1 = *p2;
*p2 = c;
++p1;
--p2;
}
printf("p:%s \n", p);
}
//========================
此处应用指针加一个临时变量将字符串进行反转,如有更好的的方法请多多指教 |
|