-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreverseAword.cpp
More file actions
55 lines (50 loc) · 934 Bytes
/
reverseAword.cpp
File metadata and controls
55 lines (50 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* reverseAword.cpp
*
* Created on: 22-Jun-2017
* Author: baliyan
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
void reverseS(char * start, char * end);
void reverseWord(char *s){
char *wordbegin=s;
char *temp=s;
while(*temp)
{
cout<<"char in temp -->"<<*temp<<endl;
temp++;
cout<<"char in temp++ -->"<<*temp<<endl;
if(*temp=='\0')
{
reverseS(wordbegin,temp-1);
}
else if(*temp==' ')
{
reverseS(wordbegin,temp-1);
wordbegin=temp+1;
}
}
cout<<"Final String is -->"<<s<<endl;
reverseS(s,temp-1);
}
void reverseS(char * begin, char * end){
char temp;
cout<<"char in begin -->"<<*begin<<endl;
cout<<"char in end -->"<<*end<<endl;
while(begin<end){
temp=*begin;
*begin++=*end;
*end--=temp;
}
cout << "String in reverseS"<< begin<<endl;
}
int main()
{
char s[]="It is my Country";
char *temp=s;
reverseWord(s);
std::cout<<s<<std::endl;
}