strpbrk
來自 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)。令
T
為不合格字元物件型別。- 如果
dest
的型別為 const T*,則返回型別為 const char*。 - 否則,如果
dest
的型別為 T*,則返回型別為 char*。 - 否則,行為未定義。
- 如果
如果 dest 或 breakset 不是指向以空字元結尾的位元組字串的指標,則行為未定義。
目錄 |
[編輯] 引數
dest | - | 指向要分析的以空字元結尾的位元組字串的指標 |
breakset | - | 指向包含要搜尋的字元的以空字元結尾的位元組字串的指標 |
[編輯] 返回值
指向 dest 中同時也在 breakset 中的第一個字元的指標,如果不存在這樣的字元,則返回空指標。
[編輯] 注意
名稱代表“字串指標斷點”,因為它返回一個指向第一個分隔(“斷點”)字元的指標。
[編輯] 示例
執行此程式碼
#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 strpbrk 函式(p: 待定)
- C17 標準 (ISO/IEC 9899:2018)
- 7.24.5.4 strpbrk 函式(p: 待定)
- C11 標準 (ISO/IEC 9899:2011)
- 7.24.5.4 strpbrk 函式(p: 368)
- C99 標準 (ISO/IEC 9899:1999)
- 7.21.5.4 strpbrk 函式(p: 331)
- C89/C90 標準 (ISO/IEC 9899:1990)
- 4.11.5.4 strpbrk 函式
[編輯] 另請參見
返回由另一個位元組字串中找到的字元組成的最大初始段的長度 僅由另一個位元組字串中未找到的字元組成 (函式) | |
查詢字元的第一次出現 (函式) | |
(C11) |
查詢位元組字串中的下一個標記 (函式) |
C++ 文件,關於 strpbrk
|