HP C/iX Library Reference Manual (30026-90004)
346 Chapter5
HP C/iX Library Function Descriptions
strpbrk
strpbrk
Returns a pointer to the location in
s1
of the first occurrence of any member of the
character set
s2
.
Syntax
#include <string.h.>
char *strpbrk(const char *
s1
, const char *
s2
);
Parameters
s1
A pointer to a null-terminated character string to be searched.
s2
A pointer to a null-terminated character string containing a character set.
Return Values
x A character pointer to the first occurrence of a character from
s2
in string
s1
.
NULL A character from the character set
s2
is not found.
Description
The strpbrk function scans null-terminated string
s1
, stopping when it finds a character
from the supplied character set
s2
.
Example
This example uses strpbrk() to parse embedded numerical data from user-supplied input
data. For simplicity, assume that the following conventions are used:
• Positive numbers do not begin with +;
• Fractional numbers always begin with zero, as in 0.25;
• The first occurrence of a digit in the string signals the beginning of the number to be
read.
The following code fragment does the job:
char line[100], *chrs = "-0123456789", *ptr;
float value;
⋮
ptr = strpbrk(line, chrs);
⋮
The character pointer chrs is initialized to point to a string of characters that might
introduce the embedded number. The strpbrk function then finds the first occurrence of
one of these characters in line and returns a pointer to that location in ptr. Finally, ptr is