Skip to content

Commit

Permalink
resolve issue #75 (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
vineet8588 authored and AkshayCHD committed Oct 23, 2018
1 parent 1a4f5b2 commit e0c0270
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions programs/C/reverse_string.c
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));
}

0 comments on commit e0c0270

Please sign in to comment.