Created
March 13, 2013 02:47
-
-
Save ikegami-yukino/5149006 to your computer and use it in GitHub Desktop.
インプレイス処理で文字列を反転する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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