当前位置:网站首页>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:

边栏推荐
- 测试点等同于测试用例吗
- IO stream basics
- 图解LeetCode——1161. 最大层内元素和(难度:中等)
- 07-SDRAM :FIFO控制模块
- JSP out.println()方法具有什么功能呢?
- Pytorch seq2seq 模型架构实现英译法任务
- 鲲鹏编译调试插件实战
- 2022/08/01 学习笔记 (day21) 泛型和枚举
- How to find new potential projects?Tools recommended
- Constructor, this keyword, method overloading, local variables and member variables
猜你喜欢
随机推荐
07-SDRAM :FIFO控制模块
面试:简单介绍你参与的一个项目
2022/08/01 Study Notes (day21) Generics and Enums
Arduino 基础语法
一文概览最实用的 DeFi 工具
An Enhanced Model for Attack Detection of Industrial Cyber-Physical Systems
els 方块边界变形处理
Collection of NFT tools
IO流基础
微软电脑管家V2.1公测版正式发布
Industrial control network intrusion detection based on automatic optimization of hyperparameters
What does the errorPage attribute of the JSP page directive do?
poker question
IP Core: FIFO
uni-app project summary
SphereEx Miao Liyao: Database Mesh R&D Practice under Cloud Native Architecture
如何设计循环队列?快进来学习~
Ansible中的任务执行控制
Constructor, this keyword, method overloading, local variables and member variables
06-SDRAM :SDRAM控制模块








![[Solution] Emqx startup under win10 reports Unable to load emulator DLL, node.db_role = EMQX_NODE__DB_ROLE = core](/img/c8/d7183330ee86c2cae9c21fecb2805b.png)
