C语言拆分字符串strtok

Example
/* STRTOK.C: In this program, a loop uses strtok
 * to print all the tokens (separated by commas
 * or blanks) in the string named "string".
 */
#include <string.h>
#include <stdio.h>
char string[] = "A string/tof ,,tokens/nand some  more tokens";
char seps[]   = " ,/t/n";
char *token;
void main( void )
{
   printf( "%s/n/nTokens:/n", string );
   /* Establish string and get the first token: */
   token = strtok( string, seps );
   while( token != NULL )
   {
      /* While there are tokens in "string" */
      printf( " %s/n", token );
      /* Get next token: */
      token = strtok( NULL, seps );
   }
}
本文为“老吴笔记”的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注