Latest web development tutorials

Cライブラリ関数 - はstrtok()

C標準ライブラリ -  <string.hの> C標準ライブラリ- <string.hの>

説明

Cライブラリ関数は、char *はstrtok(のchar * strの、のconstのchar *文字delim)区切り文字として文字列の文字列str、delimをセットに分解します。

声明

ここで、()文strtok関数です。

char *strtok(char *str, const char *delim)

パラメータ

  • STR -小さな文字列の文字列の集合に分解されます。
  • DELIM -セパレーターを含むC文字列。

戻り値

何の検索文字列が、それはNULLポインタを返していない場合、この関数は、分解された最後の部分文字列を返します。

次の例では、はstrtok()関数が使用されている示しています。

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

int main()
{
   const char str[80] = "This is - www.w3cschool.cc - website";
   const char s[2] = "-";
   char *token;
   
   /* 获取第一个子字符串 */
   token = strtok(str, s);
   
   /* 继续获取其他的子字符串 */
   while( token != NULL ) 
   {
      printf( " %s\n", token );
    
      token = strtok(NULL, s);
   }
   
   return(0);
}

それでは、以下になります上記のプログラムを、コンパイルして実行してみましょう:

This is 
www.w3cschool.cc 
website

C標準ライブラリ -  <string.hの> C標準ライブラリ- <string.hの>