Skip to content

Instantly share code, notes, and snippets.

@elvinio
Last active August 29, 2015 14:15
Show Gist options
  • Save elvinio/c63b3c42baf4e725bf23 to your computer and use it in GitHub Desktop.
Save elvinio/c63b3c42baf4e725bf23 to your computer and use it in GitHub Desktop.
Reverse a string in place in different languages
// C
#include <stdio.h>
int main(void){
char string[] = "elvino";
int len = strlen(string);
int mid = len / 2;
len--;
int i = 0;
char tmp;
while(i!=mid){
tmp = *(string + i);
*(string + i) = *(string + len - i);
*(string + len - i) = tmp;
i++;
}
puts(string);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment