看到strtok不再支持了,改用strsep,记录一下:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char s[] = "today is very good! and very shine.";
char *ss = strdup(s);
char *t, *de = " !.";
while (1)
{
t = strsep(&ss, de);
if(t==NULL)
break;
if(strlen(t))
printf("word=%s, len=%d\n", t, strlen(t));
}
return 0;
}
/* 输出:
word=today, len=5
word=is, len=2
word=very, len=4
word=good, len=4
word=and, len=3
word=very, len=4
word=shine, len=5
*/
文章介绍了在C语言中,由于strtok不再受支持,开发者应改用strsep进行字符串分割,通过示例展示了如何使用strsep分解字符串并打印单词及其长度。
5780

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



