strpbrk
From cppreference.com
| ヘッダー <string.h> で定義 |
||
| char *strpbrk( const char *dest, const char *breakset ); |
(1) | |
| /*QChar*/ *strpbrk( /*QChar*/ *dest, const char *breakset ); |
(2) | (C23以降) |
1 ) 終端ヌル文字で終わる `dest` が指すバイト文字列を、終端ヌル文字で終わる `breakset` が指すバイト文字列中の任意の文字と照合し、その文字へのポインタを返します。
2) 上記 (1) の型汎用(type-generic)関数です。
T は未修飾の文字型とします。destの型が const T* の場合、戻り値の型は const char* です。- それ以外の場合、
destの型が T* の場合、戻り値の型は char* です。 - それ以外の場合、動作は未定義です。
dest または `breakset` が終端ヌル文字で終わるバイト文字列へのポインタでない場合、動作は未定義です。
目次 |
[編集] パラメータ
| dest | - | 解析対象のヌル終端バイト文字列へのポインタ |
| breakset | - | 検索対象の文字を含むヌル終端バイト文字列へのポインタ |
[編集] 戻り値
dest 内の、`breakset` 内にも存在する最初の文字へのポインタ。そのような文字が存在しない場合はヌルポインタ。
[編集] 備考
名前は「string pointer break」の略です。これは、区切り文字(「break」)の最初の文字へのポインタを返すためです。
[編集] 例
このコードを実行
#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
[編集] 参考文献
- C23標準 (ISO/IEC 9899:2024)
- 7.24.5.4 The strpbrk function (p: TBD)
- C17標準 (ISO/IEC 9899:2018)
- 7.24.5.4 The strpbrk function (p: TBD)
- C11標準 (ISO/IEC 9899:2011)
- 7.24.5.4 The strpbrk function (p: 368)
- C99標準 (ISO/IEC 9899:1999)
- 7.21.5.4 The strpbrk function (p: 331)
- C89/C90標準 (ISO/IEC 9899:1990)
- 4.11.5.4 The strpbrk function
[編集] 関連項目
| 以下から成る最大の初期セグメントの長さを返す 別のバイト文字列に含まれない文字のみ (関数) | |
| 最初に出現する文字を見つける (関数) | |
| (C11) |
バイト文字列内の次のトークンを見つける (関数) |
| C++ ドキュメント (`strpbrk` について)
| |