面试题目: 输入字符串“I am a student”,要求输出字符串“student a am I”
#include <stdio.h>
void main()
{
char src[] = "I am a stdutent";
char *temp_start = src;
char *temp_end = src;
while (*temp_end != '\0')
{
temp_end++;
}
temp_end--;
char temp;
while (temp_start < temp_end)
{
temp = *temp_start;
*temp_start = *temp_end;
*temp_end = temp;
temp_start++;
temp_end--;
}
//reverseal all
char *index = src;
printf("The src value is %s\n", src);
while (true)
{
temp_start = index;
while (*index != '\0' && *index != ' ')
{
++index;
}
temp_end = --index;
index++;
while (temp_start < temp_end)
{
temp = *temp_start;
*temp_start = *temp_end;
*temp_end = temp;
temp_start++;
temp_end--;
}
if (*index != '\0')
{
++index;
}
else
{
break;
}
}
printf("The src value is %s\n", src);
}