C Program to Reverse a String Using strrev() Function (strrev() Function in C Language)
The strrev() function is used to reverse a string. It changes the order of characters in a string so that the last character becomes the first. strrev() is not a standard C library function. It is supported by some compilers, such as older Turbo C environments.
strrev() फंक्शन का उपयोग किसी String को उल्टा (Reverse) करने के लिए किया जाता है। इसमें String का अंतिम Character पहला और पहला Character अंतिम बन जाता है। strrev() Standard C Library Function नहीं है। यह कुछ Compilers जैसे पुराने Turbo C में उपलब्ध होता है।
Syntax
strrev(string);Example:
char str[] = "COMPUTER";strrev(str);printf("%s", str);
Output:
RETUPMOCC Program Using strrev() Function
#include <stdio.h>#include <string.h>int main(){char str[100];printf("Enter a string: ");fgets(str, sizeof(str), stdin);str[strcspn(str, "\n")] = '\0';strrev(str);printf("Reversed string: %s", str);return 0;}
Output
Enter a string: COMPUTERReversed string: RETUPMOC
Explanation
- A character array
stris declared to store the string.String स्टोर करने के लिए Character Arraystrबनाया गया है। fgets()accepts a string from the user.fgets()यूजर से String इनपुट लेता है।strcspn()removes the newline character.strcspn()Newline Character को हटाता है।strrev(str)reverses the original string.strrev(str)Original String को Reverse करता है।printf()displays the reversed string.printf()Reverse हुई String को प्रदर्शित करता है।
Important Points
strrev()reverses a string.It modifies the original string.
It is not part of the standard C library.
It may not work in modern compilers such as GCC.
महत्वपूर्ण बिंदु:
strrev()String को Reverse करता है।यह Original String में बदलाव करता है।
यह Standard C Library का हिस्सा नहीं है।
यह GCC जैसे आधुनिक Compilers में उपलब्ध नहीं हो सकता।
Comments
Post a Comment