Skip to content

Commit a69840b

Browse files
committed
ReverseAword
1 parent 71b3423 commit a69840b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

reverseAword.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* reverseAword.cpp
3+
*
4+
* Created on: 22-Jun-2017
5+
* Author: baliyan
6+
*/
7+
#include <iostream>
8+
#include <stdio.h>
9+
#include <string.h>
10+
void reverseS(char * start, char * end);
11+
void reverseWord(char *s){
12+
char *wordbegin=s;
13+
char *temp=s;
14+
while(*temp)
15+
{
16+
temp++;
17+
if(*temp=='\0')
18+
{
19+
reverseS(wordbegin,temp-1);
20+
}
21+
else if(*temp==' ')
22+
{
23+
reverseS(wordbegin,temp-1);
24+
wordbegin=temp+1;
25+
}
26+
}
27+
28+
reverseS(s,temp-1);
29+
}
30+
void reverseS(char * begin, char * end){
31+
char temp;
32+
while(begin<end){
33+
temp=*begin;
34+
*begin++=*end;
35+
*end--=temp;
36+
37+
}
38+
}
39+
40+
int main()
41+
{
42+
char s[]="It is my Country";
43+
char *temp=s;
44+
reverseWord(s);
45+
std::cout<<s<<std::endl;
46+
}
47+
48+
49+

0 commit comments

Comments
 (0)