1 #define _CRT_SECURE_NO_WARNINGS 2 #include<stdio.h> 3 #include<stdlib.h> 4 #include<string.h> 5 6 int inverse(char *str1,char *str2) 7 { 8 char *p1 = str1; 9 char *p2 = str2; 10 while (p1 < p2) 11 { 12 char c = *p1; 13 *p1 = *p2; 14 *p2 = c; 15 16 ++p1; 17 --p2; 18 } 19 return 0; 20 } 21 int main() 22 { 23 char buf[] = "abcdefg"; 24 char *p1 = buf; 25 char *p2 = buf + strlen(buf) - 1; 26 printf("原字符串是:%s\n", buf); 27 inverse(p1, p2); 28 printf("字符串反轉後:%s\n", buf); 29 system("pause"); 30 return 0; 31 }