strpbrk [ HP C/iX Library Reference Manual ] MPE/iX 5.0 Documentation
HP C/iX Library Reference Manual
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);
sscanf(ptr, "%f", &value);
:
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
passed to sscanf(), which interprets ptr as if it were a pointer to the
beginning of a string from which input is to be taken. The number is
read correctly because ptr points to the beginning of a number, and
because the f conversion terminates at the first inappropriate character.
See Also
strchr(), strrchr(), ANSI C 4.11.5.4, POSIX.1 8.1
MPE/iX 5.0 Documentation