---
title: "how to reverse the word sequence in a sentence?"
author: "standalone"
date: "2010-07-06T22:01:45Z"
tags: []
categories: ["编程语言"]
slug: "how-to-reverse-the-word-sequence-in-a-sentence"
draft: false
lastmod: "2010-07-06T22:01:45Z"
id: 706956
url: "https://standalone.iteye.com/blog/706956"
---

For example, &quot;Welcome you to Beijing&quot; is reversed into &quot;Beijing to you Welcome&quot;

```
void ReverseString(char *s, int start, int end)
 2{
 3    while (start < end)
 4    {
 5        if (s[start] != s[end])
 6        {
 7            s[start] ^= s[end];
 8            s[end] ^= s[start];
 9            s[start] ^= s[end];
10        }
11                
12        start++;
13        end--;
14    }
15}
16
17
void ReverseByWords(char *s, int len, char seperator)
{
19    int start = 0, end = 0;
20
21    ReverseString(s, start, len - 1);
22
23    while (end < len)
24    {
25        if (s[end] != seperator)
26        {
27            start = end;
28
29            while (end < len && s[end] != seperator)
30                end++;
31            end--;
32
33            ReverseString(s, start, end);
34        }
        
          end++;

          }//while
} 
```