两行代码实现字符串倒置
#include <stdio.h> #include <string.h> void reverse(char *p) { char c, *p1, *p2; for (p1=p, p2=p+strlen(p)-1; p1<p2; c=*p1, *p1=*p2, *p2=c, p1++, p2--); } /**test**/ int main() { char p[4] = {'a','b','c','\0'}; reverse(p); puts(p); return 0; }