Created
June 18, 2014 01:46
-
-
Save larry-liu/9d0e06ea7f6761fd32ee to your computer and use it in GitHub Desktop.
CC1.2(Reverse)
This file contains hidden or 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> | |
#include <stdlib.h> | |
void reverse(char* str); | |
int main(){ | |
char* str = malloc(256); | |
strcpy(str, "this is for test"); | |
printf("%s\n",str); | |
reverse(str); | |
printf("%s\n", str); | |
free(str); | |
return 0; | |
} | |
void reverse(char* str) { | |
int len = strlen(str); | |
int i = 0; | |
char temp; | |
for(i = 0; i < (len+1)/2 ; i++) { | |
temp = str[i]; | |
str[i] = str[len - 1 - i]; | |
str[len - 1 - i] = temp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for your comments in https://gist.github.com/asdw3276/39b2a443c62773fca357 ~
But string in java is immutable, so i have to create a new string and return this new string.