Skip to content

Instantly share code, notes, and snippets.

@salmanwahed
Last active November 7, 2016 19:21
Show Gist options
  • Save salmanwahed/c01e100536d10181461a631741e31e57 to your computer and use it in GitHub Desktop.
Save salmanwahed/c01e100536d10181461a631741e31e57 to your computer and use it in GitHub Desktop.
Reversing a string.
# include<stdio.h>
# include<string.h>
# define SWAP(a, b) {char tmp; tmp=a; a=b; b=tmp;}
int main(){
char str[80];
int len, i;
scanf("%[^\n]*c", str);
len = strlen(str);
for (int i=0; i<(len/2); i++){
SWAP(str[i], str[len-(i+1)]);
// printf("Pass %d: %s\n", i+1, 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