类似于异或运算
#include <stdio.h>
void swap_char(char *e1, char* e2) {
char c;
c = *e1, *e1 = *e2, *e2 = c;
}
char *reverse_str(char *s) {
char *p = s;
char *q = s;
char *r = s;
do {
if (*p == ' ' || *p=='\0') {
r = p;
--p;
while (q<p) {
swap_char(q, p);
++q, --p;
}
q = r+1;
p = r;
}
++p;
} while (*r != '\0');
q = s;
p = p-2;
while (q<p) {
swap_char(q, p);
++q, --p;
}
return s;
}
int main() {
char s[] = "I am a student. ";
puts(s);
reverse_str(s);
puts(s);
return 0;
}