strpbrk - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# strpbrk

From cppreference.com
< c‎ | string‎ | byte

Defined in header `<string.h>` |  |
char* strpbrk( const char* dest, const char* str ); |  |

Finds the first character in byte string pointed to by `dest`, that is also in byte string pointed to by `str`.

### [edit] Parameters

dest | - | pointer to the null-terminated byte string to be analyzed
str | - | pointer to the null-terminated byte string that contains the characters to search for

### [edit] Return value

Pointer to the first character in `dest`, that is also in `str`, or NULL if no such character exists.

### [edit] Example

Run this code

    #include <stdio.h>
    #include <string.h>

    int main(void)
    {
        char* input = "hello world friend of mine";
        char* space = " ";
        char* pos = input;
        int word_counter = 0;

        do {
            pos = strpbrk(pos, space);
            word_counter++;
            pos ? pos++ : pos;
            printf("%d\n", word_counter);
        } while (pos != NULL);

        return 0;
    }

Output:

    1
    2
    3
    4
    5

### [edit] See also

strcspn | returns the length of the maximum initial segment that consists of only the characters not found in another byte string (function) [edit]
strchr | finds the first occurrence of a character (function) [edit]
C++ documentation for strpbrk

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/string/byte/strpbrk&oldid=70098"