-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a4f5b2
commit e0c0270
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//Program to reverse a string in C | ||
#include<stdio.h> | ||
char* reverseString(char []); | ||
|
||
char* reverseString(char str[1000]) | ||
{ | ||
static char reversed[1000]; | ||
int i,length; | ||
//Getting lenth of the string | ||
for(i=0;str[i]!='\0';i++); | ||
length=i; | ||
|
||
//Creating a string "reversed" with the elements of string str in reverse order | ||
for(i=length-1;i>=0;i--) | ||
{ | ||
reversed[length-i-1]=str[i]; | ||
} | ||
return reversed; | ||
} | ||
void main() | ||
{ | ||
char str[1000]; | ||
printf("Enter a string-"); | ||
scanf("%s",str); | ||
printf("Reversed string is-%s\n",reverseString(str)); | ||
} |