Skip to content

Instantly share code, notes, and snippets.

@ikegami-yukino
Created March 13, 2013 02:47
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 ikegami-yukino/5149006 to your computer and use it in GitHub Desktop.
Save ikegami-yukino/5149006 to your computer and use it in GitHub Desktop.
インプレイス処理で文字列を反転する
#include<stdio.h>
#define NULL_LENGTH 4
char* reverse(char* text){
int i, length = sizeof text - NULL_LENGTH;
for(i = length;i > (length / 2);i--){
*(text+(i)) = *(text+(i)) ^ *(text+(length-i));
*(text+(length-i)) = *(text+(i)) ^ *(text+(length-i));
*(text+(i)) = *(text+(i)) ^ *(text+(length-i));
}
return text;
}
int main(){
char st[10] = "abcde";
char *s = st;
printf("%s\n",s);
printf("%s\n",reverse(s));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment