码迷,mamicode.com
首页 > 其他好文 > 详细

Reverse Words in a String

时间:2014-11-05 19:15:30      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   for   sp   div   

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 }

效果图:

bubuko.com,布布扣

Reverse Words in a String

标签:style   blog   http   io   color   ar   for   sp   div   

原文地址:http://www.cnblogs.com/udld/p/4076765.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!