关于strtok函数
函数原型:
char *strtok(char * strToken, const char *strDelimit)
参数说明:
strToken:源字符串,即待分割的串
strDelimit:strToken会根据这里的每个字符进行分割
返回值:
指向第一段被截取出来的字符串的指针,如果没有找到,则返回NULL。
调用说明:
(1)第一次调用strtok时,第一个参数是strToken。以后再调用时,第一个参数必须是NULL
(2)调用strtok后,源字符串会被修改
(3)strtok不是一个线程安全的函数
1: char str[] = "now # is the time for all # good men to come to the # aid of their country";2: char delims[] = "#";3: char *result = NULL;4: result = strtok( str, delims );5: while( result != NULL )6: {7: printf( "result is \"%s\"\n", result );8: result = strtok( NULL, delims );9: }
这个函数的应用:
HDU 2526 和 HDU 1106
#include<cstdio>#include<cstring>#include<algorithm>#define MAXN 1010using namespace std;char str[MAXN],*p;int num[MAXN];int main(){while (~scanf("%s",str)){int cnt=0;p=strtok(str,"5");while (p){num[cnt++]=atoi(p);p=strtok(NULL,"5");}sort(num,num+cnt);for(int i=0;i<cnt;i++)if(i+1==cnt) printf("%d\n",num[i]);else printf("%d ",num[i]);}return 0;}
#include<cstdio>#include<cstring>#include<cctype>#define MAXN 150using namespace std;char str1[MAXN],str2[MAXN];int main(){int t;char *p;scanf("%d",&t);getchar();while (t--){int cnt=0;gets(str1);p=strtok(str1," ");while (p){str2[cnt++]=toupper(*p);p=strtok(NULL," ");}str2[cnt]=0;printf("%s\n",str2);}return 0;}
关于strtok函数的更多相关文章
- shell脚本调用C语言之字符串切分之strtok函数
今天上午在写一个需求,要求的比较急,要求当天完成,我大致分析了一下,可以采用从shell脚本中插入一连串的日期,通过调用proc生成的可执行文件,将日期传入后台数据库,在数据库中进行计算.需要切分日期 ...
- strtok函数 分类: c++ 2014-11-02 15:24 214人阅读 评论(0) 收藏
strtok函数是cstring文件中的函数 strtok函数是cstring文件中的函数 其功能是截断字符串 原型为:char *strtok(char s[],const char *delin) ...
- strtok函数读写冲突问题
先上测试代码 #include "stdafx.h" #include <iostream> using namespace std; int _tmain(int a ...
- 字符串函数之Strtok()函数
Strtok()函数详解: 该函数包含在"string.h"头文件中 函数原型: char* strtok (char* str,constchar* delimiters ) ...
- STRTOK函数和STRTOK_R函数
STRTOK函数和STRTOK_R函数 注:本文转载自博客园,感谢作者整理! 1.一个应用实例 网络上一个比较经典的例子是将字符串切分,存入结构体中.如,现有结构体 typedef struct pe ...
- popen strtok 函数的使用
FILE * popen ( const char * command , const char * type ); int pclose ( FILE * stream ); type 参数只能 ...
- [转载]strtok函数和strtok_r函数
1.一个应用实例 网络上一个比较经典的例子是将字符串切分,存入结构体中.如,现有结构体 typedef struct person{ char name[25]; char sex[1 ...
- 温故而知新-strtok函数
温故而知新-strtok函数 记得之前没见过这个函数,是把字符串分割成更小的字符串 来个例子就是比较鲜明了 $string = "Hello world. Beautiful day tod ...
- 用strtok函数分割字符串
用strtok函数分割字符串 需要在loadrunner里面获得“15”(下面红色高亮的部分),并做成关联参数. //Body response 内容: <BODY><; PRE&g ...
- lr中用strtok函数分割字符串
需要在loadrunner里面获得“15”(下面红色高亮的部分),并做成关联参数. ,6,5,0,4,0,3,0,3,2,0,0,0,1 用web_reg_save_param取出“8,7,5,15, ...
随机推荐
- 使用python发送163邮件 qq邮箱
使用python发送163邮件 def send_email(title, content): import smtplib from email.mime.multipart import MIME ...
- SSM项目启动报错:Failed to read candidate component class
SSM项目启动报错:Failed to read candidate component class 换成3.1又没有问题,换成3.2又不行,查看编译环境用的是1.8,将1.8降为1.7,问题解决,服 ...
- C++——Struct 和 Union区别
1.在存储多个成员信息时,编译器会自动给struct第个成员分配存储空间,struct 可以存储多个成员信息,而Union每个成员会用同一个存储空间,只能存储最后一个成员的信息. 2.都是由多个不同的 ...
- CSS margin属性
例子: p{ margin:2cm 4cm 3cm 4cm; } 结果如下: margin-top是上外边距 margin-right是右外边距 margin-bottom是下外边距 margin-l ...
- std::locale与boost::locale的学习
1. 什么是facet, locale facet ['fæsɪt]的原意,是宝石切割出来的一个平面. locale[ləʊˈkæl],表示本地化, locale the container that ...
- C# Windows服务相关
代码及注释 ServiceController sc = new ServiceController("gupdatem"); sc.Stop();//停止服务 sc.Start( ...
- 两种接口传送数据协议(xml和json)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/tianyazaiheruan/article/details/37659983 规范性接口开发 ...
- vue swiper上下无缝轮播
参考:https://www.jianshu.com/p/5e5e59065e9c 效果: index.html: <link href="https://cdn.bootcss.co ...
- Android studio的ERROR: Unable to resolve dependency for 错误
同事拷贝一份工程给我,在我这里用AS编译的时候出现这个错误.按照网上很多的方法都不行,后来终于可以. 在AS中打开FILE->Setting->gradle->,在右边service ...
- Xcode使用篇-重新安装Xcode
卸载Xcode sudo rm -rf /Applications/Xcode.app sudo rm -rf /Library/Preferences/com.apple.dt.Xcode.plis ...