码迷,mamicode.com
首页 > 其他好文 > 详细

strsep函数实现及测试

时间:2017-08-14 23:31:07      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:ring   while   main   printf   word   amp   ret   not   实现   

#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函数实现及测试

标签:ring   while   main   printf   word   amp   ret   not   实现   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!