In this C program, we will learn how to write a program to reverse a string without using strrev() using a Pointer.
Here is the code of the program to reverse a string without using strrev() using a Pointer.
/* C program to Reverse a String without using strrev() using Pointer*/
#include <stdio.h>
#include <string.h>
char* reverse_String(char *Str)
{
static int i = 0;
static char RevStr[10];
if(*Str)
{
reverse_String(Str + 1);
RevStr[i++] = *Str;
}
return RevStr;
}
void main()
{
char Str[100], temp;
int i, j, len;
printf("Enter a String: ");
gets(Str);
printf("Reverse String is = = %s", reverse_String(Str));
}
Enter a String: Tutorialsrack
Reverse String is = = kcarslairotuT
--------------------------------
Process exited after 4.721 seconds with return value 36
Press any key to continue . . .
Comments