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:

RETUPMOC

C 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: COMPUTER
Reversed string: RETUPMOC

Explanation

  1. A character array str is declared to store the string.
    String स्टोर करने के लिए Character Array str बनाया गया है।

  2. fgets() accepts a string from the user.
    fgets() यूजर से String इनपुट लेता है।

  3. strcspn() removes the newline character.
    strcspn() Newline Character को हटाता है।

  4. strrev(str) reverses the original string.
    strrev(str) Original String को Reverse करता है।

  5. 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

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025