C++ Program To Reverse String Without Using String Functions














































C++ Program To Reverse String Without Using String Functions



Description:
Given a string, this program helps to reverse it.
First length of the string is calculated using eol.
Then the first character is swapped with last and second with second last and so on.
After the loop is finished we get the required string.

Program Code: 
#include <iostream> using namespace std; void RevString (char S[]) { int i; int l=0; for ( i=0;S[i]!='\0';i++) { l++; } cout<<"\nLength:"<<l; for (i=0;i<l/2;i++) { char t=S[i]; S[i]=S[l-i-1]; S[l-i-1]=t; } cout<<"\nReversed String:"; for ( i=0;S[i]!='\0';i++) { cout<<S[i]; } } int main() { char S[25]={"CppSecrets"}; cout<<S; RevString(S);
return 0;
}
Output:



More Articles of Avikrit Kohli:

Name Views Likes
C++ Program To Implement Simpsons 3/8th rule 360 2
C++ Program To Reverse String Without Using String Functions 382 20
C++ Program To Reverse Line In Text File 1243 1
C++ Program To Reverse Each Word In Text File 324 1
C++ Program To Read Text File Word By Word 1428 1
C++ Program To Create And Display Text File 303 1
C++ Program To Find Root Using Newton-Raphson Method 5394 11
C++ Program To Find Root Using Bisection Method 1125 1
C++ Program For Cohen Sutherland Clipping Algorithm 1839 1
To Sort Array Of Integers Using Bubble,Insertion And Selection Sort 317 1
C++ Program To Delete Element In Array At Particular Position 517 1
C++ Program To Insert Element In Array At Given Position 698 1
C++ Program To Implement Stack Using Arrays 331 1
Python Program To Add Source Code of A Webpage 239 1
Python Program To Extract Data From Excel 267 1
C++ Program To Find Sum Of Fibonacci Series Using Recursion 459 1
Program To Display Level Order Transversal Using Queue 254 1
C++ Program To Find The Minimum In Subarray Of Size k Using Deque 267 1
C++ Program To Sort Stack Recursively 857 1
C++ Program To Reverse Stack Recursively 262 1
C++ Program To Insert At Bottom Of Stack Using Recursion 266 1
C++ Program To Create Tower Of Hanoi 2427 1
C++ Program To Convert Infix To Postfix Expression Using Stack 10945 3
C++ Program To Balance Parenthesis Using Stack 963 1
C++ Program To Implement Queue Using Array 2256 2
C++ Program To Sort Two Arrays And Inserting Result In Third array 258 1
C++ Program To Find Length Of Linked List 675 1
C++ Program To Search An Element Recursively In Linked List 293 1
C++ Program To Reverse Linked List Recursively 1153 1
To Find Negation of Number Using Operator Overloading 241 1
C++ Program to create Hangman 2639 1
C++ Program to Swap two numbers without using third variable 318 2

Comments