#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
数组的方式实现前后反转的
*/
void str_reverse(char* str)
{
char temp; //中间变量
int low = 0; //前面的变量
int high = strlen(str) - 1;
while (low < high)
{
temp = str[low];
str[low] = str[high];
str[high] = temp;
high--;
low++;
}
printf("%s\n", str);
}
/*
指针方式实现
*/
void str_point(char* str)
{
char temp; //中间变量
char* p = str; //前面的指针
int n = strlen(str) - 1;
char* q = &str[n]; //后面的指针
while (p < q)
{
temp = *p;
*p = *q;
*q = temp;
p++;
q--;
}
printf("%s\n", str);
}
int main(void)
{
char str[] = "China0123";
str_reverse(str);
str_point(str);
system("pause");
return 0;
}