字符串翻转,单词内不翻转。如I am from Chongqing->Chongqing from am I
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 void reverse(char *str, int beg, int end); 6 void reverseSentece(char *str); 7 int main() 8 { 9 char str[128]; 10 gets_s(str,128); 11 reverseSentece(str); 12 puts(str); 13 system("pause"); 14 return 0; 15 } 16 17 void reverse(char *str, int beg, int end) 18 { 19 char temp; 20 if(str == NULL) 21 return; 22 while(beg <= end) 23 { 24 temp = str[beg]; 25 str[beg] = str[end]; 26 str[end] = temp; 27 beg++; 28 end--; 29 } 30 } 31 32 void reverseSentece(char *str) 33 { 34 int beg = 0; 35 int end = 0; 36 if(str == NULL) 37 return; 38 //翻转整个句子 39 reverse(str,0,strlen(str)-1); 40 //局部翻转 41 while(str[end] != '