Linux系统库函数之strsep

/* lib/string.c */

strsep函数用于分割字符串,函数原型如下:

char *strsep(char **s, const char *ct);

s为指向欲分割的字符串,ct为分隔符,函数将返回分隔符前面的字符串,s将指向分隔符之后的字符串,实例如下:

#include <stdio.h>

#include <string.h>

int main(void)
{
        char s[] = "hello world!";
        char *p = s;
        char *d = " ";
        printf("%s\n", strsep(&p, d));
        printf("%s\n", p);

        return 0;
}

函数打印如下:

hello
world!


该函数同strtok函数类似,用来替换strtok函数的,原因如下:

 * -  Added strsep() which will replace strtok() soon (because strsep() is
 *    reentrant and should be faster). Use only strsep() in new code, please.

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值