读书笔记: 字符串(string)操作 getStrLen, Backwards 输出 1 2 3 4 5 6 void print_string(char *s){ while(*s){ printf("%c", *s); s++; } } 获取长度 1 2 3 4 5 6 7 8 9 int getStrLen(char *s){ int i = 0; while( *s ) { i++; s++; } return i; } 翻转 1 2 3 4 5 6 7 8 9 10 11 12 13 void strRev(char *s) { char temp, *end; end = s + getStrLen(s) - 1; while( end > s) { temp = *s; *s = *end; *end = temp; --end; ++s; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 void backwards(char s[],int index) { if(s[index]){ backwards(s, index+1); printf("%c",s[index]); } } void backwards_p(char *s) { if(*s){ backwards_p(++s); printf("%c",*s); } }