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

边栏推荐
- 2022/08/01 Study Notes (day21) Generics and Enums
- IO流基础
- Don't know about SynchronousQueue?So ArrayBlockingQueue and LinkedBlockingQueue don't and don't know?
- JSP如何使用page指令让JSP文件支持中文编码呢?
- DFS详解
- async/await 原理及执行顺序分析
- 当奈飞的NFT忘记了Web2的业务安全
- [HCIP] BGP Small Experiment (Federation, Optimization)
- Business test how to avoid missing?
- 基于编码策略的电网假数据注入攻击检测
猜你喜欢

Short video SEO search operation customer acquisition system function introduction

Task execution control in Ansible

鲲鹏编译调试插件实战

【21天学习挑战赛】顺序查找和二分查找的小总结

面试:简单介绍你参与的一个项目

Double queue implementation stack?Dual stack implementation queue?

Disk and file system management

How to find new potential projects?Tools recommended

Using the "stack" fast computing -- reverse polish expression

Redis-消息发布订阅
随机推荐
What is the function of the JSP Taglib directive?
[21-Day Learning Challenge] A small summary of sequential search and binary search
What does the errorPage attribute of the JSP page directive do?
Redis - message publish and subscribe
测试用例:四步测试设计法
IO流基础
An interesting project--Folder comparison tool (1)
nodeJs--各种路径
微软电脑管家V2.1公测版正式发布
基于超参数自动寻优的工控网络入侵检测
c语言字符和字符串函数总结(二)
JSP out. The write () method has what function?
Are test points the same as test cases?
基于相关性变量筛选偏最小二乘回归的多维相关时间序列建模方法
146. LRU 缓存
When Netflix's NFTs Forget Web2 Business Security
Day11 shell脚本基础知识
Double queue implementation stack?Dual stack implementation queue?
els 方块边界变形处理
Using the "stack" fast computing -- reverse polish expression