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

被折叠的 条评论
为什么被折叠?



