Skip to content

Instantly share code, notes, and snippets.

@rr-paras-patel
Created March 13, 2016 14:49
Show Gist options
  • Save rr-paras-patel/cf0cc6642d49232539aa to your computer and use it in GitHub Desktop.
Save rr-paras-patel/cf0cc6642d49232539aa to your computer and use it in GitHub Desktop.
#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