Created
December 9, 2021 09:45
-
-
Save laughingclouds/84f9a61be1e91e6af2a214310ab4bbad to your computer and use it in GitHub Desktop.
Reverse a string in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
void strrev(char *str, char *nStr) { | |
int len = strlen(str); | |
for (int i = len - 1; i >= 0; i--) { | |
strncat(nStr, &str[i], 1); | |
} | |
} | |
int main() { | |
char str[100]; | |
printf("Enter string: "); | |
scanf("%s", str); | |
int len = strlen(str); | |
char nStr[100]; | |
strrev(str, nStr); | |
printf("%s\n", nStr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment