C String Reverse
In this section, you will study how to reverse a string. You can see in the
given example, a recursive function reverse(int i) is created. Inside
the method, we are calculating the length of a specified string using a library
function strlen(). Then string st[i] and st[strlen(st)-i-1]
are swapped as:
c= st[i];
st[i]=st[strlen(st)-i-1];
st[strlen(st)-i-1]=c;
Statements shown above will reverse the string.
Here is the code:
StringReverse.C
#include <stdio.h>
|
Output will be displayed as:
STRING~1.EXE