Searching the first character occurrence in the given string using the C strpbrk() function

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows 2003 Server Standard Edition

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info:

To do: Searching the first character occurrence in the given string using the C strpbrk() function

To show: How to use the strpbrk() C function to scan strings for characters in specified character sets

 

// Using strpbrk()/wcspbrk()/_mbspbrk() function

#include <stdio.h>

#include <string.h>

 

int main(void)

{

char *string1 = "This is a test statement";

char *string2 = "search";

printf(" Using strpbrk()\n");

printf(" ---------------\n");

printf("In \"%s\" string, a character \'%c\'\n", string2, *strpbrk(string1, string2));

printf("is the first character to appear in\n\"%s\"\n", string1);

 

return 0;

}

 

Output example:

 

Using strpbrk()

---------------

In "search" string, a character 'h'

is the first character to appear in

"This is a test statement"

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index