How to Reverse a String in C without using C Reverse String function and using either Pointers or Recursive Function.

C Program to Reverse a String without using C Reverse String function (strrev() in string.h) and using either Pointers or Recursive Function is given below:-
1) C Example program to Reverse a String using pointers :

#include<stdio.h>
int strLength(char*); // user defined function declaration or function prototype
void strReverse(char*); // UDF declr or fun proto
main()
{
char str[100];
printf("Enter a String to be Reversed :");
gets(str); // using gets() instead of scanf() because scanf() does not take space char
strReverse(str); // function with argument as string variable str calls here
printf("Reverse of given String is \"%s\".\n", str);
return 0;
}
void strReverse(char *str) // strReverse() function defines here
{
int length, c;
char *begin, *end, temp;
length = strLength(str); // function strLength() calls here and which returns integer value to be stored in "length" variable.
begin = str;
end = str;
for ( c = 0 ; c < ( length - 1 ) ; c++ )
end++;
for ( c = 0 ; c < length/2 ; c++ )
{
temp = *end;
*end = *begin;
*begin = temp;
begin++;
end--;
}
}
int strLength(char *pointer) // strLength() function defines here, which returns an integer
{
int c = 0;
while( *(pointer+c) != '\0' )
c++;
return c;
}

2) C Example program to Reverse a String using Recursive Function ( function calls itself ) :

#include<stdio.h>
#include<string.h>
void strReverse(char*,int,int);
main()
{
char str[100];
printf("Enter a String to be Reversed :");
gets(str);
strReverse(str, 0, strlen(str)-1);
printf("Reverse of given String is \"%s\".\n", str);
return 0;
}
void strReverse(char *ch, int begin, int end)
{
char a, b, c;
if ( begin >= end )
return;
c = *(ch+begin);
*(ch+begin) = *(ch+end);
*(ch+end) = c;
strReverse(ch, ++begin, --end);
}