Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions Reversing a String/src/Reversing a String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@
using namespace std;

int main() {


//Entering the string
char text[] = "Hello there!";


//calculating the size of text
int nChars = sizeof(text)-1;


//Assiging the address of text array to a pointer
char *pStart = text;
char *pEnd = text + nChars - 1;

//setting the last alphabet adrress to a pointer
char *pEnd = text + nChars - 1;

//Swapping the string into reverse string
while(pStart < pEnd) {

char save = *pStart;
Expand All @@ -28,7 +34,8 @@ int main() {
pEnd--;
}

cout << text << endl;
//printing reverse string
cout <<"\n"<<text<< endl;


return 0;
Expand Down