strsep作用http://antyoung.blog.51cto.com/2471749/655593分割字符串的.和strtok基本一样. #include #include int main() { char ptr[]={“abcdefghijklmnopqrstuvwxyz”}; char *p,*str=”m”; p=p
http://antyoung.blog.51cto.com/2471749/655593
分割字符串的.和strtok基本一样.
#include <string.h>
#include <stdlib.h>
int main()
{
char ptr[]={ “abcdefghijklmnopqrstuvwxyz “};
char *p,*str= “m “;
p=ptr;
printf( “%s\n “,strsep(&p,str));
printf( “%s\n “,p);
str= “s “;
printf( “%s\n “,strsep(&p,str));
printf( “%s\n “,p);
}
[root@shwhg test]# gcc test131.c
[root@shwhg test]# ./a.out
abcdefghijkl
nopqrstuvwxyz
nopqr
tuvwxyz
c语言里面常用的字符串分割函数有strtok和strsep //strtok示例: #include <string.h> #include <stdio.h> int main(void) { char input[16] = “abc,d”; char *p; p = strtok(input, “,”); if (p) printf(“%s\n”, p); p = strtok(NULL, “,”); if (p) printf(“%s\n”, p); return 0; } //strsep示例: #include <string.h> main() { char string[] = “words separated by spaces”; char *running; char *token; running=string; while((token = strsep (&running,” “))!=NULL) printf(“%s\n”,token); exit(0); } 注: 下面的说明摘自于最新的Linux内核2.6.29,说明了这个函数已经不再使用,由速度更快的strsep()代替 /* * linux/lib/string.c * * Copyright (C) 1991, 1992 Linus Torvalds */ /* * stupid library routines.. The optimized versions should generally be found * as inline code in <asm-xx/string.h> * * These are buggy as well.. * * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de> * – Added strsep() which will replace strtok() soon (because strsep() is * reentrant and should be faster). Use only strsep() in new code, please. * * * Sat Feb 09 2002, Jason Thomas <jason@topic.com.au>, * Matthew Hawkins <matt@mh.dropbear.id.au> * – Kissed strtok() goodbye */ |
|
今天的文章strsep作用分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/8890.html