void reverse(char* left, char* right)
{
while (left < right)
{
int tmp = *left;
*left = *right;
*right = tmp;
left++;
right--;
}
}
int main()
{
char arr[101] = { 0 };
gets_s(arr);
int len = strlen(arr);//求字符串长度
//逆置整个字符串
reverse(arr,arr+len-1);
char* start = arr;
while (*start)
{
char* end = start;
while (*end != '\0' && *end != ' ')
{
end++;
}
reverse(start, end - 1);
if (*end != '\0')
{
end++;
}
start = end;
}
printf("%s\n", arr);
return 0;
}