用指针将字符串逆序输出
// yangbocsu 2021.07.13
#include<stdio.h>
#ifndef N
#define N 20
#endif
int main()
{
char s1[N],s2[N],*p1 = s1,*p2 = s2,s3[2]={'a','b'};
int length = 0;
scanf("%s",s1);
printf("s1 = %s\n",s1);
while(*p1 != '\0') //统计字符串的长度
{
length ++;
p1 ++;
}
p1 = s1 + length - 1; //p1 = &s1[length - 1]; 将指针移到字符串尾
for(;length>=0;p1--,length--,p2++)
{
*p2 = *p1;
}
*p2 = '\0';
printf("s2 = %s\n",s2);
return 0;
}