Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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