#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
void reverse(char* start, char* end)
{
if (start == NULL || end == NULL)
{
return;
}
char tmp = '\0';
while (start < end)
{
tmp = *start;
*start = *end;
*end = tmp;
start++;
end--;
}
}
void convert(char* source)
{
if(source == NULL)
return;
char* p = source;
while (*p != '\0')
{
if (*p == ' ')
{
char* next = p + 1;
reverse(source, p - 1);
source = next;
}
p++;
}
reverse(source, p-1);
}
int _tmain(int argc, _TCHAR* argv[])
{
char s[] = "i came from chengdu.";
convert(s);
reverse(s, s+strlen(s) -1);
cout<<s<<endl;
getch();
return 0;
}