Linux C function() 參考手冊:strpbrk(查找(比對)字串中第一個出現的指定字元)

Linux C function() 參考手冊:strpbrk(查找(比對)字串中第一個出現的指定字元)

Linux C function() 參考手冊:strpbrk(查找(比對)字串中第一個出現的指定字元)

 

資料來源:http://people.cs.nctu.edu.tw/~yslin/library/linuxc/main.htm
線上執行:http://www.tutorialspoint.com/compile_c_online.php
code2html:http://tohtml.com/

 

 

相關函數
index,memchr,rindex,strpbrk,strsep,strspn,strstr,strtok
表頭文件
#include <include.h>
定義函數
char *strpbrk(const char *s,const char *accept);
函數說明
strpbrk()用來找出參數s 字符串中最先出現存在參數accept 字符串中的任意字符。
返回值
如果找到指定的字符則返回該字符所在地址,否則返回0。
範例

 

#include <string.h>
#include <stdio.h>
int main()
{
char *s="0123456789012345678901234567890";
char *p;
p=strpbrk(s,"a1 839"); /*1會最先在s字符串中找到*/
printf("%d\n",(p-s)+1);
p=strpbrk(s,"4398");/*3 會最先在s 字符串中找到*/
printf("%d\n",(p-s)+1);
return 0;
}

 

 



發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *