免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: backhead
打印 上一主题 下一主题

[故障求助] 有个弱智的问题想问 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2003-08-20 09:31 |只看该作者

有个弱智的问题想问

如果系统安装了man中的Technical Reference(一般命令帮助是Command Reference),用man 2 strtok命令就可以看。

char *strtok (String1, String2)
char *String1;
const char *String2;

Attention: Do not use the strtok subroutine in a multithreaded environment.

The strtok subroutine breaks the string pointed to by the String1 parameter into a sequence of tokens, each of which is delimited by a byte from the string pointed to by the String2 parameter. The first call in the sequence takes the String1 parameter as its first argument and is followed by calls that take a null pointer as their first argument. The separator string pointed to by the String2 parameter may be different from call to call.

The first call in the sequence searches the String1 parameter for the first byte that is not contained in the current separator string pointed to by the String2 parameter. If no such byte is found, no tokens exist in the string pointed to by the String1 parameter, and a null pointer is returned. If such a byte is found, it is the start of the first token.

The strtok subroutine then searches from the first token for a byte that is contained in the current separator string. If no such byte is found, the current token extends to the end of the string pointed to by the String1 parameter, and subsequent searches for a token return a null pointer. If such a byte is found, the strtok subroutine overwrites it with a null byte, which terminates the current token. The strtok subroutine saves a pointer to the following byte, from which the next search for a token will start. The subroutine returns a pointer to the first byte of the token.

Each subsequent call with a null pointer as the value of the first argument starts searching from the saved pointer, using it as the first token. Otherwise, the subroutine's behavior does not change.

论坛徽章:
0
12 [报告]
发表于 2003-08-20 11:49 |只看该作者

有个弱智的问题想问

[quote]原帖由 "backhead"]能否详细说说strtok的用法[/quote 发表:
     

eg: "I like this place, hehe, "

pstr = strtok("I like this place, hehe, ", ",";
//pstr == "I like this place"
pstr = strtok('\0', ",";
//pstr == "hehe"
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP