Linux strsep() 用法

本文介绍了strsep()函数,它是strtok()的升级版本,在字符串处理中非常实用。文章通过示例代码展示了如何使用该函数,并提醒使用者注意其对字符串的修改特性。此函数不能用于常量字符串且会丢失分隔符的身份。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

strsep(),作为strtok的升级版,是一个很有用的字符串处理函数

man strsep:

#include <string.h>  

     char*strsep(char **stringp, const char *delim);

Be cautious when using this function. If you do use it, note that:  

This function modifies its first argument.  

This function cannot be used on constant strings.  

The identity of the delimiting character is lost.

#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;
}
函数打印如下:helloworld!


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值