C Program To Reverse a String
Learn How To Reverse a String in C Programming Language. We have described different versions of String Reversal Program in C Language.
strrev() method is defined in the string.h header file. It is therefore, a Library Function. strrev() method is used to reverse any given string. A String is primarily an Array of Characters.
If you want to input a Multi – word String from the user, you have to use the following scanf() method.
1 | scanf("%[^\n]%*c", string); |
If you want to enter only a single word String, then you can use the following scanf() method.
1 | scanf("%s", string); |
Must Read: C Program To For String Reversal using Stack Data Structure
Method 1: C Program To Reverse a String using Library Function and Array
1 2 3 4 5 6 7 8 9 10 11 12 | #include<stdio.h> #include<string.h> int main() { char string[30]; printf("\nEnter a String:\t"); scanf("%[^\n]%*c", string); printf("\nEntered String: \t%s\n", string); printf("\nReverse of the String: \t%s\n", strrev(string)); return 0; } |
C Program To Reverse a String without String Function strrev() and For Loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include<stdio.h> #include<string.h> int main() { int count, length = 0; char string[30], temp; printf("\nEnter a String:\t"); scanf("%[^\n]%*c", string); printf("\nEntered String: \t%s\n", string); length = strlen(string) - 1; for(count = 0; count < length; count++, length--) { temp = string[count]; string[count] = string[length]; string[length] = temp; } printf("\nReverse of the String: \t%s\n", string); return 0; } |
Must Read: C Program To Sort Name String in Alphabetical Order
Output

If you have any compilation error or doubts in this C Program For String Reversal without String Functions, let us know about it in the Comment Section below.
Thanks for so easy methods of reversing a string. Can we use reverse a string using Pointers in C?
Yes! Definitely! We can use Pointers in Strings! In fact, many methods of manipulation in string uses pointers!
What is better? Reversing a String using Arrays or Reverse a String Array using Stack Data Structure. However, this C program seems more easy in implementation.
Stack is also an implementation of array. I would suggest you to understand the logic in both the C Programs To Reverse a String. Even if you know one method, it would be more than enough.