strpbrk
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <string.h> で定義
|
||
char* strpbrk( const char* dest, const char* 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)
{
const char* str = "hello world, friend of mine!";
const char* sep = " ,!";
unsigned int cnt = 0;
do {
str = strpbrk(str, sep); // find separator
if(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)
- C99 standard (ISO/IEC 9899:1999):
- 7.21.5.4 The strpbrk function (p: 331)
- C89/C90 standard (ISO/IEC 9899:1990):
- 4.11.5.4 The strpbrk function
関連項目
| 別のバイト文字列に含まれない文字のみで構成され最も長い先頭部分の長さを返します (関数) | |
| 文字が現れる最初の位置を探します (関数) | |
(C11) |
バイト文字列中の次のトークンを探します (関数) |
strpbrk の C++リファレンス
| |