Created
March 13, 2016 14:49
-
-
Save rr-paras-patel/cf0cc6642d49232539aa to your computer and use it in GitHub Desktop.
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 reverse(char *string); | |
int main() | |
{ | |
char origStr1 [] = "abcdfsdfsfd"; | |
char origStr2 [] = "a"; | |
char *origStr3 = NULL; | |
reverse(origStr1); | |
reverse(origStr1); | |
reverse(origStr1); | |
printf("%s\n",origStr1); | |
printf("%s\n",origStr2); | |
printf("%s\n",origStr3); | |
return 0; | |
} | |
void swap(char *start,char *end) | |
{ | |
char temp; | |
temp = *start; | |
*start = *end; | |
*end = temp; | |
} | |
void reverse(char *string) | |
{ | |
if(string == NULL) return; | |
if(strlen(string) < 2) return; | |
char *end = string + strlen(string) - 1; | |
while((end != string) && (end != string+1)) | |
{ | |
swap(string,end); | |
end--; | |
string++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment