#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int inverse(char *src)
{
if (src==NULL)
{
printf(“put in err”);
return -1;
}
int length = strlen(src);
char *p1 = src;
char *p2 = src + length - 1;
//printf(“p1:%d \n”, p1);
//printf(“p2:%d \n”, p2);
while (p1 < p2)
{
char c = *p1;
*p1 = *p2;
*p2 = c;
++p1;
–p2;
//p1++;
//p2–;
}
return 0;
}
//字符串翻转
int main()
{
char buf[] = “abcde”;//buf是栈区生长方向向上
/*int length = strlen(buf);
char *p1 = buf;
char *p2 = buf + length - 1;
printf(“p1:%d \n”, p1);
printf(“p2:%d \n”, p2);
while (p1<p2)
{
char c = *p1;
*p1 = *p2;
p2 = c;
++p1;
–p2;
p1++;
p2–;
}/
inverse(buf);
printf(“buf:%s \n”,buf);
printf("hello... \n");
return 0;
}