This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>.
All rights reserved.

Released under the GNU General Public License.

Return to index Return to header Previous symbol Next symbol

strpbrk

Prototype

#include <string.h>

char *strpbrk(const char *s, const char *set);

Description

Returns a pointer to the first occurrence in the string s of any character from the string set, or NULL if no character from set occurs in s.

Implementation

View source
#include <string.h>

char *strpbrk(const char *s, const char *set)
{
    const char *sp1, *sp2;

    for (sp1 = s; *sp1 != '\0'; ++sp1)
	for (sp2 = set; *sp2 != '\0'; ++sp2)
	    if (*sp1 == *sp2)
		return (char *)sp1;

    return NULL;
}

Example

View source
#include <string.h>

/*
 * Count the punctuation characters ",.;:?!" found in
 * the `s' string.
 */
int count_punct(const char *s)
{
    int count = 0;
    while ((s = strpbrk(s, ",.;:?!")) != NULL)
	++count, ++s;
    return count;
}

References

ISO C 9899:1990 7.11.5.4