// Console1018.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <sstream>
#include <string>
using namespace std;
#define N 100
void ReverseWord(char *s, int low, int high);
int main()
{
char s[] = "I am a stdudent";
int low = 0;
int high = 0;
int i = 0;
int len = 0;
int lowFlags = 0;
int highFlags = 0;
while (s[len] != '\0')
{
len++;
}
ReverseWord(s, 0, len-1);
while (s[i] != '\0')
{
if (s[i] != ' ' && lowFlags == 0)
{
low = i;
lowFlags = 1;
}
if (s[i] == ' '&& highFlags == 0)
{
high = i - 1;
highFlags = 1;
}
if (lowFlags == 1 && highFlags == 1)
{
ReverseWord(s, low, high);
lowFlags = 0;
highFlags = 0;
}
++i;
}
cout << s << endl;
}
void ReverseWord( char *s, int low, int high )
{
int i = low;
int j = high;
while (i < j)
{
swap(s[i], s[j]);
++i;
--j;
}
}