Skip to main content

Posts

Showing posts with the label Recursion

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" varia...