首页 > 其他 > 详细

strsep函数实现及测试

时间:2017-08-14 23:07:54      阅读:428      评论:0      收藏:0      [点我收藏+]
#include<stdio.h>
char *strsep(char **stringp, const char *delim)
{
    char *s;
    const char *spanp;
    int c, sc;
    char *tok;
    if ((s = *stringp)== NULL)
        return (NULL);
    for (tok = s;;) {
        c = *s++;
        spanp = delim;
        do {
            if ((sc =*spanp++) == c) {
                if (c == 0)
                    s = NULL;
                else
                    s[-1] = 0;
                *stringp = s;
                return (tok);
            }
        } while (sc != 0);
    }
    /* NOTREACHED */
}
int main()
{
        char *s3;
	char s1[] = "h,e,l,l,o,word";
	char *s2 = ",";
	char *buf;
	buf = s1;
	while((s3 = strsep(&buf,s2)) != NULL)
	{
	    printf("%s\n",s3);
	}
	return 0;

}

运行结果:
h
e
l
l
o
word

 

strsep函数实现及测试

原文:http://www.cnblogs.com/51CC-YL/p/7360363.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!