Reverse a String in CThis topic will discuss several ways to reverse a string in the C programming language. Reversing a string is the technique that reverses or changes the order of a given string so that the last character of the string becomes the first character of the string and so on. Furthermore, we can also check the Palindrome of the given string by reversing the original string. For example, we enter a string "APPLE", and then use the reverse algorithm. The reverse algorithm returns the string "ELPPA" which is completely reverse of the original string. Different ways to find the reverse of a string in the CFollowing are the various ways to find the reverse of a string in the C programming language:
Program 1: Print the reverse of a string using strrev() functionLet's consider an example to print the reverse of a string using the strrev() function. Program1.c Output Enter a string to be reversed: AMBULANCE After the reverse of a string: ECNALUBMA Program 2: Print the reverse of a string without using the library functionLet's consider an example to print the reverse of a string using user defined function. Program2.c Output Enter the string: Welcome Friends Before reversing the string: Welcome Friends After reversing the string: sdneirF emocleW Program 3: Print the reverse of a string using the recursion functionLet's consider an example to print the reverse of a string using the recursion function. Recursion function: A recursion function is a function that continuously calls the same function without using a looping statement. Program3.c Output Enter the string: LIFE INSURANCE Before reversing the string: LIFE INSURANCE After reversing the string: ECNARUSNI EFIL Program 4: Print the reverse of a string using for loopLet's consider an example to print the reverse of a string using for loop in C programming language. Program4.c Output Display a reverse string in the C: ----------------------- Enter a string to reverse order: APPLE The reverse of the original string is: ELPPA Program 5: Print the reverse of a string using while loopLet's consider an example to print the reverse of a string using while loop in C programming language. Program5.c Output Enter a string to be reversed: JAVATPOINT The reversed of the string: TNIOPTAVAJ Program 6: Print the reverse of a string using pointersLet's consider an example to print the reverse of a string using pointers in the C programming language. Program6.c Output Enter a string to be reversed: JAVATPOINT The reverse string is: TNIOPTAVAJ Program 7: Program to check whether the reverse string is a PalindromeConsider a program to check whether the given string is a palindrome or not in the C programming language. Program7.c Output Enter a string: madam madam is a palindrome string. Next TopicTwin Prime Numbers in C |