解题:
#include <stdio.h>
void reverse_string(char *str)
{
char *last_char;
for (last_char = str; *last_char != '\0'; last_char++)
{
}
last_char--;
while (str < last_char) {
char temp;
temp = *str;
*str++ = *last_char;
*last_char-- = temp;
}
}
int main()
{
char a[] = "Hello World, I love China.";
char *b = a;
reverse_string(b);
printf("%s\n", b);
return 0;
}
运行:
➜ C ./a.out
.anihC evol I ,dlroW olleH
网友评论