- 论坛徽章:
- 0
|
#include <stdlib.h>
#include <stdio.h>
int main()
{
char *org = "今天,天气很好,oh yeah!";
int len = strlen(org);
char *str = (char*)malloc(len+1);
memset(str,0,len+1);
int j = len-1;
int i = 0;
int k = 0;
int tmp_index = -1;
for(;i<len;i++){
if(isalnum(org[i])){
if(tmp_index < 0){
tmp_index = i;
}
}else{
if(tmp_index > 0){
for(k=i-1;k>=tmp_index;k--){
str[j--] = org[k];
}
}
int val = (int)org[i] & 0xFF;
if(val > 0x80 ){
str[j--] = org[i+1];
str[j--] = org[i];
i++;
}else{
str[j--] = org[i];
}
tmp_index = -1;
}
}
if(tmp_index > 0){
for(k=i-1;k>=tmp_index;k--){
str[j--] = org[k];
}
}
printf("org:%s,new str:%s\n",org,str);
free(str);
return 1;
} |
|