当前位置:网站首页>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;
}
运行结果
边栏推荐
- MySql函数
- Some thoughts on small program subcontracting and verification of uiniapp subcontracting optimization logic
- How does webapi relate to the database of MS SQL?
- MySQL function
- 传统微服务框架如何无缝过渡到服务网格 ASM
- Mysql 监控5
- Quality management of functional modules of MES management system
- 画画水族馆的应用特色及功能
- The listing of Symantec electronic sprint technology innovation board: it plans to raise 623million yuan, with a total of 64 patent applications
- Three text to speech artifacts, each of which is very practical
猜你喜欢

Three text to speech artifacts, each of which is very practical

I, 33 years old, ByteDance test development, unveiled the real income of Beijing "test post"

城市规划馆在设计制作上需要注意什么

How latex enters a matrix

【推荐系统】基于用户的协同过滤简明原理与代码实现
![[Thesis Writing] English thesis writing guide](/img/59/88d34814a88a2da19ed6a236825649.png)
[Thesis Writing] English thesis writing guide

Preliminary understanding of NVIDIA Jetson nano

Machine learning notes: time series decomposition STL

Understand the module function of MES management system

Seata 與三大平臺攜手編程之夏,百萬獎金等你來拿
随机推荐
Machinery -- nx2007 (UG) finite element analysis tutorial 1 -- simple object
MySql函数
I learned database at station B (V): DQL exercise
Tetris game based on STM32F103
第八届“互联网+”大赛 | 云原生赛道邀你来挑战
Difference between test plan and test plan
Can mango hypermedia, which "braves the wind and waves", go ashore?
HC32M0+ GPIO
Interface Association of postman
【机器学习Q&A】数据抽样和模型验证方法、超参数调优以及过拟合和欠拟合问题
Wechat applet - requestsubscribemessage:fail can only be invoked by user tap gesture
What are the top ten securities companies? In addition, is it safe to open a mobile account?
【PyTorch实战】生成对抗网络GAN:生成动漫人物头像
ES6 synchronous asynchronous execution and block level scope
Kubernetes 核心对象概览详解
Reading is the cheapest noble
Mysql 监控1
Machine learning notes: time series decomposition STL
TP-LINK configure WiFi authentication method for wireless Internet SMS
Some thoughts on small program subcontracting and verification of uiniapp subcontracting optimization logic