首页 > 代码库 > Reverse Words in a String
Reverse Words in a String
Reverse Words in a String
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue
",
return "blue is sky the
".
代码实现:
1 # include<stdio.h> 2 void TurnoverS(char* m){ 3 char* k=m; 4 int length = strlen(k); 5 char* n[100]; 6 int i=0; 7 for (; i < length; i++) 8 { 9 n[i] = k;10 for (;;k++){11 if (*k == 0)12 break;13 if (*k ==32&&*(k + 1) != 32)14 { 15 k++;16 break;17 }18 }19 if (*k == 0)20 break;21 }22 for (; i >= 0; i--)23 Wc(n[i]);24 }25 26 int Wc (char* p){27 char* k = p;28 for (;;k++){29 if (*k==32)30 break;31 if (*k==0)32 break;33 printf("%c",*k);34 }35 printf(" ");36 return 0;37 }38 void main(){39 char k[100];40 printf("Please input a string of characters that thelength below 100:\n ");41 gets_s(k,98);42 printf("%s\n", k);43 TurnoverS(k);44 system("pause");45 }
效果图:
Reverse Words in a String
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。