C语言字符串分割函数

本文介绍了如何编写一个C语言的字符串分割函数,该函数能根据分隔符列表拆分字符串。分隔符可以是单个字符或字符串,并且可以控制是否忽略连续分隔符产生的空串,以及是否保留分隔符本身。使用该函数生成的结果需要用户自行释放内存。
摘要由CSDN通过智能技术生成

      自己写了一个字符串分割函数,可以根据提供的分隔符串列表将指定的字符串分割为若干个字符串,分隔符可以是单个字符也可以是字符串,可以设定是否压缩分隔符串(即当两个或者两个以上分隔符串连续出现时不生成空串),也可以设定是否把查找到的分隔符串也插入到结果中。需要注意的是结果是动态分配的内存,使用完毕后需要自己释放。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/**
 * Split a string into some strings according to a list of separators.
 *
 * @Param dest						out: storage the strings has be split.
 * @Param count						out: the number of strings has be split successfully, 0 for failed to split.
 * @Param s_str						in:  the strings for split.
 * @Param separator					in:  the list of split separators.
 * @Param number_separator			in:  the numbers of separators.
 * @Param compress_separator		in:  will be create a empty string when two split adjacent
 *										 if compress_separator > 0 and not for compress_separator == 0
 * @Param keep_separator			in:  the separators will be put into parameter 'dest' if keep_separator > 0
 */
int strsplit(char **
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值