This program Reverse string in C entered by the user. For example if a user enters a string “reverse me” then on reversing the string will be “em esrever”. We show you four different methods to reverse string the first one uses strrev library function of string.h header file, second without using strrev and in third we make our own function to reverse string using pointers, reverse string using recursion and Reverse words in string. If you are using first method then you must include string.h in your program.
[ad type=”banner”]C programming code
/* String reverse in c*/
Output of program:
C program to reverse string without using function
Below code does not uses strrev library function to Reverse string in C. First we calculate the length of string using strlen function and then assigns characters of input string in reverse order to create a new string using a for loop. You can also calculate length of string without using strlen. We use comma operator in for loop to initialize multiple variables and increment/decrement variables.
[ad type=”banner”]C program to reverse a string using pointers
Now we will invert string using pointers or without using library function strrev.
program to reverse string in C using recursion
[ad type=”banner”]In recursion method we swap characters at the begin and at the end and then move towards the middle of the string. This method is inefficient due to repeated function calls but useful in practicing recursion.
this is really useful for me