相关疑难解决方法(0)

strtok()如何将字符串拆分为C中的标记?

请解释我的strtok()功能工作.手册说它把字符串分成了令牌.我无法从手册中了解它实际上是做什么的.

我添加了手表str*pch检查其工作情况,当第一个while循环发生时,内容str仅为"this".如何在屏幕上显示下面显示的输出?

/* strtok example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] ="- This, a sample string.";
  char * pch;
  printf ("Splitting string \"%s\" into tokens:\n",str);
  pch = strtok (str," ,.-");
  while (pch != NULL)
  {
    printf ("%s\n",pch);
    pch = strtok (NULL, " ,.-");
  }
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

Splitting string "- This, a sample string." into tokens:
This
a
sample
string

c string split token strtok

101
推荐指数
7
解决办法
32万
查看次数

标签 统计

c ×1

split ×1

string ×1

strtok ×1

token ×1