Skip to content

Instantly share code, notes, and snippets.

@larry-liu
Created June 18, 2014 01:46
Show Gist options
  • Save larry-liu/9d0e06ea7f6761fd32ee to your computer and use it in GitHub Desktop.
Save larry-liu/9d0e06ea7f6761fd32ee to your computer and use it in GitHub Desktop.
CC1.2(Reverse)
#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;
}
}
@asdw3276
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment