当前位置:网站首页>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:
边栏推荐
猜你喜欢
扑克牌问题
632. 最小区间
Arduino Basic Syntax
Short video SEO optimization tutorial Self-media SEO optimization skills and methods
不了解SynchronousQueue?那ArrayBlockingQueue和LinkedBlockingQueue不会也不知道吧?
不要用jOOQ串联字符串
TCL:在Quartus中使用tcl脚本语言进行管脚约束
这 4 款电脑记事本软件,得试试
Double queue implementation stack?Dual stack implementation queue?
Redis的集群模式
随机推荐
含外部储能的电力系统暂态稳定分布式控制
bgp 聚合 反射器 联邦实验
辨析内存函数memset、memcmp、memmove以及memcpy
中缀转后缀、前缀表达式快速解决办法
Are test points the same as test cases?
22.支持向量机—高斯核函数
微软电脑管家V2.1公测版正式发布
How does JSP use request to get the real IP of the current visitor?
[Solution] Emqx startup under win10 reports Unable to load emulator DLL, node.db_role = EMQX_NODE__DB_ROLE = core
460. LFU 缓存
els block deformation
After an incomplete recovery, the control file has been created or restored, the database must be opened with RESETLOGS, interpreting RESETLOGS.
NFT工具合集
Identify memory functions memset, memcmp, memmove, and memcpy
NodeJs, all kinds of path
Quick solution for infix to suffix and prefix expressions
Day11 shell脚本基础知识
When Netflix's NFTs Forget Web2 Business Security
How to find new potential projects?Tools recommended
async/await 原理及执行顺序分析