strtok
1、
Int main(void)
{
char *tmp = NULL;
Char *remotebuf=”0\r\n”;
tmp = strtok(remotebuf, DELIM); 执行出现段错误。
}
2、
Int main(void)
{
char *tmp = NULL;
char *remotebuf = NULL;
remotebuf = (char *)malloc(10);
strcpy(remotebuf, "0\r\n");
tmp = strtok(remotebuf, DELIM); 执行则没有问题。
}
3、
Int main(void)
{
Char *remotebuf=”0\r\n”;
Printf(“%s\n”,remotebuf); 执行没有问题
}
vi strtok
#include<string.h>
#include<stdio.h>
int main(void)
{
char *p,coname[20]=":name:name1",*colon=":",*name;
printf("%s\n",coname);
p=strtok(coname,colon);
printf("%s\n",p);
printf("%s\n",coname);
name=strtok(NULL,colon);
printf("%s\n",name);
return 0;
}
root@dbaudit-desktop:~/xcj# gcc -o strtok strtok.c
root@dbaudit-desktop:~/xcj# ./strtok
:name:name1
name
:name
name1
当strtok()在参数s的字符串中发现参数delim中包涵的分割字符时,则会将该字符改为\0 字符。因此第一次和第二次打印coname结果不同,数组默认结尾是\0。。
因此使用char *strtok(char s[], const char *delim);函数之前,要先把s拷贝出来一份。
strtok的更多相关文章
- strsep和strtok_r替代strtok
char *strtok(char *str, const char *delim) 会修改数据源.外部加锁才线程安全(strtok执行结束再解锁执行另一个strtok循环知道工作完成) 主要是以互斥 ...
- loadrunner中切割strtok字符串
http://blog.sina.com.cn/s/blog_7ee076050102vamg.html http://www.cnblogs.com/lixiaohui-ambition/archi ...
- strtok&strsep
strtok,strtok_r,strsep--extract tokens from strings Tje strsep() function was introduced as a replac ...
- 字符串分割函数 STRTOK & STRTOK_R (转)
1.一个应用实例 网络上一个比较经典的例子是将字符串切分,存入结构体中.如,现有结构体 typedef struct person{ char name[25]; char sex[1 ...
- strtok和strtok_r
1.strtok()函数的用法 函数原型:char *strtok(char *s, const char *delim); Function:分解字符串为一组字符串.s为要分解的字符串,delim为 ...
- 浅谈strtok
原型:char *strtok(char *s, char *delim); 功能:分解字符串为一组标记串.s为要分解的字符串,delim为分隔符字符串. 说明:首次调用时,s必须指向要分解的字符串, ...
- 函数strtok
char* strtok(char *str, const char*delim) char *strtok_r(char *str, const char *delim, char **savept ...
- [转]关于strtok和strtok_r函数的深度研究
在linux环境下,字符串分割的函数中,大家比较常用的是strtok函数,这个函数用处很大,但也有一些问题,以下将深度挖掘一下这个函数的用法,原理,实现,其次,该函数是不可再入函数,但是在linux ...
- hdu1106 字符串水题strtok()&&strchr()&&sscanf()+atoi()使用
字符串的题目 用库函数往往能大大简化代码量 以hdu1106为例 函数介绍 strtok() 原型: char *strtok(char s[], const char *delim); 功能: 分解 ...
随机推荐
- ContextMenuOpening 事件
ContextMenuOpening事件,不能在将要触发的目标ContextMenu中触发,只能包含 这个ContextMenu的父控件中触发该事件. 在ListView中,希望控制右键弹出菜单时,可 ...
- cocos2d-x学习笔记------动画人物跑起来吧!
学习总结: 1.sprintf用来格式化字符串 2.CCSpriteFrame:: frameWithTexture通过图片名创建的时候需要的参数Texture2D创建使用CCTextureCache ...
- VirtualBox 安装虚拟机时出现错误 VT-x features locked or unavailable in MSR.
修改安装好的虚拟机的cup的个数重新启动的时候报了上述错误. 参考博文:http://blog.csdn.net/zklth/article/details/7019990 错误:VT-x featu ...
- Starting MySQL.. ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).
[root@localhost ~]# cd /usr/local/mysql [root@localhost mysql]# chown -R mysql.mysql . [root@loc ...
- 学习hash_map从而了解如何写stl里面的hash函数和equal或者compare函数
---恢复内容开始--- 看到同事用unordered_map了所以找个帖子学习学习 http://blog.sina.com.cn/s/blog_4c98b9600100audq.html (一)为 ...
- Servlet的getContextPath(), getServletPath(), getRequestURI(), getRealPath("/")
假定web application 名称为news,你在浏览器中输入请求路径: http://localhost:8080/news/main/list.jsp 则执行下面向行代码后打印出如下结果: ...
- JSON和JSONP,也许你会豁然开朗,含jQuery用例
前言: 说到AJAX就会不可避免的面临两个问题,第一个是AJAX以何种格式来交换数据?第二个是跨域的需求如何解决?这两个问题目前都有不同的解决方案,比如数据可以用自定义字符串或者用XML来描述,跨域可 ...
- c# 获取MP3和AMR文件格式的时长
//网上摘录整理private long GetAMRFileDuration(string fileName) { ; FileStream fs = new FileStream(fileName ...
- jquery delegate
代码如下: $('#container').delegate('a','click',function(){alert('That tickles!')} JQuery扫描文档查找$('#cont ...
- 【弱省胡策】Round #6 String 解题报告
感觉这个题好神啊. 首先我们只管 $a = b$ 的情况,那么我们自然就可以把这个串对 $a$ 取模,然后用 KMP 求出能弄出几个其他的 B 串. 具体就是把串先倍长,然后倒过来,然后求 $Next ...