CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
【经验总结】不能实施并行处理的情况 浅谈并行编程中的任务分解模式
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

strtok用起来的结果怎么跟帮助上的不一样?

楼主Sachow(SC)2002-05-23 20:45:51 在 C/C++ / C语言 提问

帮助文档上说如果strtok找不到分隔符分隔的子串就会返回NULL,但是我发现它会返回整个源串,这是怎么一回事?  
   
  #include   <stdio.h>  
  #include   <string.h>  
   
  void   main()  
  {  
          char   Src[]="Msg=War,Time=Now";  
          char   *s="";  
          s   =   strtok(Src,";");     //找";"  
          printf("%s\n",s);  
  }  
   
  结果返回"Msg=War,Time=Now"!!! 问题点数:30、回复次数:3Top

1 楼systemid(早睡早起身体好)回复于 2002-05-23 21:09:54 得分 0

On   the   first   call   to   strtok,   the   function   skips   leading   delimiters   and   returns   a   pointer   to   the   first   token   in   strToken,   terminating   the   token   with   a   null   character.   More   tokens   can   be   broken   out   of   the   remainder   of   strToken   by   a   series   of   calls   to   strtok.   Each   call   to   strtok   modifies   strToken   by   inserting   a   null   character   after   the   token   returned   by   that   call.   To   read   the   next   token   from   strToken,   call   strtok   with   a   NULL   value   for   the   strToken   argument.   The   NULL   strToken   argument   causes   strtok   to   search   for   the   next   token   in   the   modified   strToken.   The   strDelimit   argument   can   take   any   value   from   one   call   to   the   next   so   that   the   set   of   delimiters   may   vary.Top

2 楼steedhorse(晨星)回复于 2002-05-23 21:13:05 得分 15

第一次应该返回整个串,MSDN里说:  
  They   return   NULL   when   no   more   tokens   are   found.  
  下一次应该返回空。Top

3 楼dgj(我是一匹狼)回复于 2002-05-23 21:53:06 得分 15

返回整个串很正常啊,没有分割符分割他那不就是整个串就是一部分了吗?Top

4 楼Sachow(SC)回复于 2002-05-24 09:42:04 得分 0

这样理解倒是也有道理,但不是我要的结果,我希望第一次找不到就返回NULL,只好自己多写点代码了……Top

相关问题

  • post,get 结果不一样.
  • 两个程序结果一样吗?
  • 为什么AND的结果不一样呢?
  • 反汇编,一样的代码,不一样的结果
  • 一样的程序,不一样的结果
  • 【Ajax】读一样的XML,结果却不一样?
  • 为什么一样的算法,不一样的结果??
  • 送分啦!!!!怎么结果跟我想的结果不一样??
  • 按delete后的结果和delete+shift的结果一样
  • 如何做象IE帮助一样的压缩型的html帮助?

关键词

  • null
  • strtok
  • strtoken
  • 返回
  • tokens
  • argument
  • call
  • next

得分解答快速导航

  • 帖主:Sachow
  • steedhorse
  • dgj

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
惹火投票。。火热进行中...
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
CSDN网站24小时值班电话:13552009689
Copyright © 2000-2009, CSDN.NET, All Rights Reserved
GongshangLogo