如:“hello world” 变为 “world hello”
// test.cpp : main project file.
#include "stdafx.h"
#include<iostream>
using namespace System;
using namespace std;
char * stringreverse(char str[],int start,int end)
{
char tmp;
while(start<end)
{
tmp = str[start];
str[start] = str[end];
str[end] = tmp;
start++;
end--;
}
return str;
}
int reversewords(char str[])
{
int len = strlen(str);
int start = 0;
int end = 0;
stringreverse(str,start,len-1);
do
{
start = end;
while(str[end] != ' '&&end<len)
end++;
end--;
stringreverse(str,start,end);
end+=2;
}while(end<len);
return 1;
}
int main(int argc, char* argv[])
{
char str[100]="hello world" ;
reversewords(str);
printf("%s\n",str);
return 0;
}