Skip to content

Instantly share code, notes, and snippets.

@zachwhaley
Last active August 29, 2015 13:57
Show Gist options
  • Save zachwhaley/9433891 to your computer and use it in GitHub Desktop.
Save zachwhaley/9433891 to your computer and use it in GitHub Desktop.
C program to reverse a string
#include <stdio.h>
#include <string.h>
void strrev(char *str)
{
char tmp, *end;
if (str) {
end = str + strlen(str) - 1;
while (str < end) {
tmp = *str;
*str++ = *end;
*end-- = tmp;
}
}
}
int main(int argc, char *argv[])
{
char *str;
int i;
for (i = 1; i < argc; i++) {
str = argv[i];
strrev(str);
printf("%s\n", str);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment