当前位置:网站首页>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;
}
运行结果
边栏推荐
- Sentinel source code analysis Chapter 9 - core process - lookprocesschain finding resource processing chain
- Visual studio 2017 cannot open the include file: 'qopenglfunctions_3_3_core': no such file or directory
- Machinery -- nx2007 (UG) finite element analysis tutorial 2 -- assembly
- Embedded exit (review and release)
- Quality management of functional modules of MES management system
- 3-6sql injection website instance step 5: break through the background to obtain web administrator permissions
- STC89C52 single chip microcomputer simple calculator design and code demonstration
- Rubymine development tool, refactoring and intention operation
- Cookie加密13
- c语言选择,循环概述
猜你喜欢

Analysis of IM instant messaging development technology on modern web

Seata et les trois plateformes travaillent main dans la main pour programmer Summer, un million de bonus vous attend

cookie加密11

Ansible ad-hoc temporary command

Cookie加密12

【535. TinyURL 的加密与解密】

STC89C52 single chip microcomputer simple calculator design and code demonstration

Some thoughts on small program subcontracting and verification of uiniapp subcontracting optimization logic

Stimulus reports reporting tool, stimulus creates and builds reports

Sentinel source code analysis Part 7 - sentinel adapter module - Summary
随机推荐
The listing of Symantec electronic sprint technology innovation board: it plans to raise 623million yuan, with a total of 64 patent applications
Is the numpy index the same as the image index?
How to view the size of all files in a folder?
In depth analysis of a large number of clos on the server_ The root of wait
Machine learning notes: time series decomposition STL
MySQL installation steps (detailed)
“乘风破浪”的芒果超媒,能上岸吗?
阅读,是最廉价的高贵
画画水族馆的应用特色及功能
Wechat applet - requestsubscribemessage:fail can only be invoked by user tap gesture
Unity编辑器随机生成物体,更换场景之后物体丢失问题解决
JS anti shake and throttling
Seata et les trois plateformes travaillent main dans la main pour programmer Summer, un million de bonus vous attend
第八届“互联网+”大赛 | 云原生赛道邀你来挑战
VIM editor common instructions
Varnish 基础概览8
Quality management of functional modules of MES management system
ES6 one line code for array de duplication
js内容混淆,返回内容加密
ES6 synchronous asynchronous execution and block level scope