题解 | 字符串反转
#include <stdio.h> #include <string.h> void swap(char *a,char *b){ char temp ; temp = *a; *a = *b; *b = temp; } void reverse(char *s,int start,int end){ int i,j; i = start;j = end; while(i < j){ swap(&s[i],&s[j]); i++;j--; } } int main() { char s[1200];int i; fgets(s,sizeof(s),stdin); int len = strlen(s); reverse(s, 0 ,len - 2); for(i = 0;i < len - 1;i++){ printf("%c",s[i]); } return 0; }