strpbrk
提供: cppreference.com
ヘッダ <string.h> で定義 | ||
char* strpbrk(constchar* dest, constchar* breakset ); | ||
breakset
の指すヌル終端バイト文字列内の任意の文字を dest
の指すヌル終端バイト文字列からスキャンし、その文字を指すポインタを返します。
dest
または breakset
がヌル終端バイト文字列を指すポインタでない場合、動作は未定義です。
目次 |
[編集]引数
dest | - | 解析するヌル終端バイト文字列を指すポインタ |
breakset | - | 検索する文字を含むヌル終端バイト文字列を指すポインタ |
[編集]戻り値
breakset
にも含まれる dest
内の最初の文字を指すポインタ、またはそのような文字が存在しない場合はヌルポインタ。
[編集]ノート
関数名の由来は「string pointer break」です。 最初の区切り (break) 文字を指すポインタを返すためです。
[編集]例
Run this code
#include <stdio.h>#include <string.h> int main(void){constchar* str ="hello world, friend of mine!";constchar* sep =" ,!"; unsignedint cnt =0;do{ str = strpbrk(str, sep);// find separatorif(str) str +=strspn(str, sep);// skip separator++cnt;// increment word count}while(str &&*str); printf("There are %u words\n", cnt);}
出力:
There are 5 words
[編集]参考文献
- C11 standard (ISO/IEC 9899:2011):
- 7.24.5.4 The strpbrk function (p: 368)