函数原型: char *strpbrk( const char *string, const char *strCharSet );
wchar_t *wcspbrk( const wchar_t *string, const wchar_t *strCharSet );
函数原型:
char * strpbrk(const char * cs,const char * ct)
{
const char *sc1,*sc2;
for( sc1 = cs; *sc1 != '\0'; ++sc1) {
for( sc2 = ct; *sc2 != '\0'; ++sc2) {
if (*sc1 == *sc2)
return (char *) sc1;
}
}
return NULL;
}
功能:依次检验
字符串s1中的字符,当被检验字符在字符串s2中也包含时,则停止检验,并返回该字符位置,空字符NULL不包括在内。
说明:返回s1中第一个满足条件的字符的
指针,如果没有匹配字符则返回空指针NULL。
用途:在源字符串(s1)中找出最先含有搜索字符串(s2)中任一字符的位置并返回,若找不到则返回空指针。
csdn:例子
/* STRPBRK.C */
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[100] = "The 3 men and 2 boys ate 5 pigs\n";
char *result;
/* Return pointer to first 'a' or 'b' in "string" */
printf( "1: %s\n", string );
result = strpbrk( string, "0123456789" );
printf( "2: %s\n", result++ );
result = strpbrk( result, "0123456789" );
printf( "3: %s\n", result++ );
result = strpbrk( result, "0123456789" );
printf( "4: %s\n", result );
}
输出:
1: The 3 men and 2 boys ate 5 pigs
2: 3 men and 2 boys ate 5 pigs
3: 2 boys ate 5 pigs
4: 5 pigs
2: 3 men and 2 boys ate 5 pigs
3: 2 boys ate 5 pigs
4: 5 pigs