2022年7月9日星期六

C strpbrk

char *strpbrk(const char *string1, const char *string2);

IBM 說明

The strpbrk() function locates the first occurrence in the string pointed to by string1 of any character from the string pointed to by string2.

我的理解:strpbrk函式會回傳string2中的第一個字元,第一次出現在string1中的指標

  1. int main(void)
  2. {
  3. char *string1 = "Test string1 for learn";
  4. char *chars = "le";
  5. char *result;
  6. result = strpbrk(string1, chars);
  7. printf("The first occurrence of any of the characters \"%s\" in "
  8. "\"%s\" is \"%s\"\n", chars, string1, result);
  9. }

執行結果




參考資料

https://zh.m.wikipedia.org/zh-tw/String.h#%E5%87%BD%E6%95%B0

https://www.ibm.com/docs/en/i/7.1?topic=functions-strpbrk-find-characters-in-string

沒有留言:

發佈留言

打賞按讚