当前位置:网站首页>String splitting function strtok exercise
String splitting function strtok exercise
2022-08-02 00:32:00 【BSP Junior Primary School Monk】
Write a program that displays command line arguments in reverse word order, that is, if the command line argument
is see you later, the program should display later you see
Analysis: This question can be done by using the string splitting function, because each word needs to be separated by a space ' ', we can use this as a starting point to separate each word with the splitting function strtok, and theThe separated string is stored into another pointer array once, and then the pointer array is printed in reverse order.
Code:
/*3. Write a program that displays command line arguments in reverse word order, i.e. if the command line argumentsis see you later, the program display should be later you see*/#include #include int main(){char str[] = "hello world ni hao world";puts(str);char *p[100];char *ret;int i = 0;ret = strtok(str, " ");while (ret != '\0'){i++;p[i] = ret;ret = strtok(NULL, " ");}while (i >= 0){printf("%s ", p[i]);i--;}return 0;}
Run result:
边栏推荐
- 基于超参数自动寻优的工控网络入侵检测
- Detailed explanation of JSP request object function
- 460. LFU cache
- JSP out.print()和out.write()方法的不同之处
- els 长条变形
- Disk and file system management
- What is the function of the JSP out.println() method?
- 如何设计循环队列?快进来学习~
- SphereEx Miao Liyao: Database Mesh R&D Practice under Cloud Native Architecture
- What does the errorPage attribute of the JSP page directive do?
猜你喜欢
These 4 computer notepad software, you have to try
Redis-消息发布订阅
[HCIP] BGP Small Experiment (Federation, Optimization)
Graphical LeetCode - 1161. Maximum Sum of In-Layer Elements (Difficulty: Moderate)
Knowing the inorder traversal of the array and the preorder traversal of the array, return the postorder history array
Short video SEO optimization tutorial Self-media SEO optimization skills and methods
08-SDRAM: Summary
Redis - message publish and subscribe
Are test points the same as test cases?
Day11 shell脚本基础知识
随机推荐
Disk and file system management
Cyber-Physical System State Estimation and Sensor Attack Detection
c语言字符和字符串函数总结(二)
短视频seo搜索优化主要内容
不要用jOOQ串联字符串
uni-app project summary
go语言标准库fmt包怎么使用
Redis - message publish and subscribe
bgp 聚合 反射器 联邦实验
146. LRU cache
NodeJs, all kinds of path
Automatic conversion of Oracle-style implicit joins to ANSI JOINs using jOOQ
146. LRU 缓存
460. LFU 缓存
Interview high-frequency test questions solution - stack push and pop sequence, effective parentheses, reverse Polish expression evaluation
当奈飞的NFT忘记了Web2的业务安全
IP Core: FIFO
ROS dynamic parameters
利用“栈”快速计算——逆波兰表达式
Day11 shell脚本基础知识