int main() { char arr[100] = { 0 };//定义一个字符数组,用来存储输入的字符串 gets(arr);//I like Beijing. int length = strlen(arr); reverse(arr,arr+length-1);//.gnijieB ekil I
char* start; char* end; start = arr; end = start;
while (*start)//只要开始字符不为空字符就继续 { end = start; while ((*end != ' ') && (*end != '\0')) { end++; } reverse(start, end - 1); if (*end != '\0') end++;//跳过空格 start = end; }
//遍历最终结果 int i = 0; for (i = 0; i < length; i++) { printf("%c", arr[i]); }