版本1
void reverse(char *str)
{
int i;
int j = strlen(str);
char temp;
for (i=0; i<j;i++,j--)
{
temp = str[i];
str[i] = str[j-1];
str[j-1] = temp;
}
}
版本2
void reverse(char *str)
{
int i;
int j = strlen(str);
char temp;
for (i=0; i<j/2;i++)
{
temp = str[i];
str[i] = str[j-i-1];
str[j-i-1] = temp;
}
}
版本3
void reverse(char *str)
{
char temp;
char *last_char;
for (last_char = str; *last_char != '\0'; last_char++)
;
last_char--;
while (str < last_char)
{
temp = *str;
*str++ = *last_char;
*last_char-- = temp;
}
}
版本4
void reverse(char *str)
{
char temp;
char *last_char;
for (last_char = str; *last_char != '\0'; last_char++)
;
last_char--;
while(str<last_char)
{
*str = *str ^ *last_char;
*last_char = *str ^ *last_char;
*str = *str ^ *last_char;;
str++;
last_char--;
}
}