Skip to content

Instantly share code, notes, and snippets.

@kira924age
Created January 18, 2018 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kira924age/978367ee75c7d6fbfc0aa7f798b4630b to your computer and use it in GitHub Desktop.
Save kira924age/978367ee75c7d6fbfc0aa7f798b4630b to your computer and use it in GitHub Desktop.
Reverse string.
#include <stdio.h>
#include <string.h>
void swap(char *x, char *y) {
char tmp; tmp = *x;
*x = *y;
*y = tmp;
}
void *reverse(char *s) {
char *p = s, *q = s + strlen(s) - 1;
int t = p - q;
while ((p - q) * t >= 0) {
swap(p, q);
*p++; *q--;
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment