当前位置:网站首页>C语言 说反话
C语言 说反话
2022-06-30 01:25:00 【Martin の Blog】

算法设计思路
- 使用fget方法获取输入的字符串
- 判断字符串中是否有回车,如果有回车直接将该字符设定位指针尾,防止回车的输出
- 判断字符串中的空格,如果空格不为空,则开始打印空格后面的字符,并将当前指针设置位尾指针
- 注意strrchr函数返回的是最后一次出现的字符
- 打印剩余的字符,也就是第一个字符内容
代码
#include <stdio.h>
#include <string.h>
int main(){
char s[100];
char *p;
fgets(s, 100, stdin);
if((p=strrchr(s, '\n')) != NULL){
*p = '\0';
}
while((p=strrchr(s, ' ')) != NULL){
printf("%s ", p+1);
*p = '\0';
}
printf("%s", s);
return 0;
}
运行结果
边栏推荐
- Can mango hypermedia, which "braves the wind and waves", go ashore?
- 【图神经网络】图分类学习研究综述[3]:图分类方法评价及未来研究方向
- Using tsne to visualize the similarity of different sentences
- Varnish 基础概览3
- ES6 one line code for array de duplication
- Tetris game based on STM32F103
- Shell spec date format
- What are the top ten securities companies? In addition, is it safe to open a mobile account?
- HC32M0+ GPIO
- 第八届“互联网+”大赛 | 云原生赛道邀你来挑战
猜你喜欢

How to seamlessly transition from traditional microservice framework to service grid ASM

Seata 与三大平台携手编程之夏,百万奖金等你来拿

81. 搜索旋转排序数组 II

Mechanical --nx2007 (UG) -- gap analysis (interference inspection)
![Cantilever beam calculation [matlab code]](/img/f6/9a1338e00777e91f6c340eae9d52ba.jpg)
Cantilever beam calculation [matlab code]

Solving plane stress problem with MATLAB
![[535. encryption and decryption of tinyurl]](/img/b7/7748febe30852ca428fe86b045e9ca.png)
[535. encryption and decryption of tinyurl]

3-6sql injection website instance step 5: break through the background to obtain web administrator permissions

Resizekit2.net size and resolution independent

Seata 與三大平臺攜手編程之夏,百萬獎金等你來拿
随机推荐
挖财的课程靠谱吗,让开户安全吗?
传统微服务框架如何无缝过渡到服务网格 ASM
Varnish 基础概览3
城市规划馆在设计制作上需要注意什么
Vant weave - remove (clear) < van button > button component Click to display gray background effect
Pytroch Learning Notes 6: NN network layer convolution layer
Mysql 监控2
2020-12-03
Internal class usage scenarios, syntax and principle explanations
Cub school learning: manual query and ADC in-depth use
cookie加密11
Kubernetes core object overview details
Interface Association of postman
Cookie加密10
【图神经网络】图分类学习研究综述[3]:图分类方法评价及未来研究方向
画画水族馆的应用特色及功能
Varnish 基础概览2
Cloud, IPv6 and all-optical network
Taguchi experimental method
js返回内容被unicode编码