https://blog.csdn.net/qq_40840749/article/details/81782061
- printf("%s",&str[i]) 是输出第i+1 指针指向的字符串,以’\0’结束。
- 在C++ 编译器提交全错,用C提交正确,暂时不懂。
- 是否可以直接写成 printf("%s ", &str[i+1]);
- gets() 是读取字符串,接受空格,以enter结束,并舍弃;getchar()是读取字符,不会舍弃最后enter
https://blog.csdn.net/xiao_yanci/article/details/80588934
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main(){
char str[81];
gets(str);
for(int i = strlen(str) - 1; i >= 0; i--){
if(str[i] == ' '){
printf("%s", &str[i+1]);
printf("%c", str[i]);
str[i] = '\0';
}
if(i == 0){
printf("%s", &str[i]);
}
}
return 0;
}