Skip to content

Instantly share code, notes, and snippets.

@KushalP
Created April 5, 2010 21:59
Show Gist options
  • Select an option

  • Save KushalP/356954 to your computer and use it in GitHub Desktop.

Select an option

Save KushalP/356954 to your computer and use it in GitHub Desktop.
#include <stdio.h>
/* This function assumes the passed pointer points to a valid, zero-terminated string */
void reverse(char *s)
{
char *t = s;
while (*t != '\0') t++;
while (s < t)
{
int c = *s;
*s++ = *--t;
*t = c;
}
}
int main()
{
char text1[] = "asdf", text2[] = "";
reverse (text1);
printf ("'%s'\n", text1);
reverse (text2);
printf ("'%s'\n", text2);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment