当前位置:网站首页>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:
边栏推荐
- JSP how to obtain the path information in the request object?
- 构造方法,this关键字,方法的重载,局部变量与成员变量
- 字符串分割函数strtok练习
- els block deformation judgment.
- Cyber-Physical System State Estimation and Sensor Attack Detection
- 已知中序遍历数组和先序遍历数组,返回后序遗历数组
- Business test how to avoid missing?
- Simpson's paradox
- An Enhanced Model for Attack Detection of Industrial Cyber-Physical Systems
- CRS 管理与维护
猜你喜欢
随机推荐
poker question
Cyber-Physical System State Estimation and Sensor Attack Detection
基于编码策略的电网假数据注入攻击检测
MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界
Grid false data injection attacks detection based on coding strategy
Unknown CMake command "add_action_files"
nodeJs--各种路径
Knowing the inorder traversal of the array and the preorder traversal of the array, return the postorder history array
鲲鹏编译调试插件实战
Statement执行update语句
els block deformation
06-SDRAM :SDRAM控制模块
Async/await principle and execution sequence analysis
nodeJs--mime模块
Disk and file system management
els 方块变形
链上治理为何如此重要,波卡Gov 2.0又会如何引领链上治理的发展?
What is the function of the JSP Taglib directive?
Mean Consistency Tracking of Time-Varying Reference Inputs for Multi-Agent Systems with Communication Delays
短视频SEO搜索运营获客系统功能介绍