11.5. Search Functions

11.5.1. The memchr function

Synopsis
#include <string.h>

void *memchr (const void * s , int c , size_t n );

Description

The memchr function locates the first occurrence of c (converted to an unsigned char) in the initial n characters (each interpreted as an unsigned char) of the object pointed to by s.

Returns

The memchr function returns a pointer to the located character, or a null pointer if the character does not occur in the object.

Implementation Notes

None.

11.5.2. The strchr function

Synopsis
#include <string.h>

char *strchr (char * s , int c );

Description

The strchr function locates the first occurrence of c (converted to a char) in the string pointed to by s. The terminating null character is considered to be part of the string.

Returns

The strchr function returns a pointer to the located character, or a null pointer if the character does not occur in the string.

Implementation Notes

None.

11.5.3. The strcspn function

Synopsis
#include <string.h>

size_t strcspn (char * s1 , char * s2 );

Description

The strcspn function computes the length of the maximum initial segment of the string pointed to by s1 which consists entirely of characters not from the string pointed to by s2.

Returns

The strcspn function returns the length of the segment.

See Also

Section 11.5.6

Implementation Notes

None.

11.5.4. The strpbrk function

Synopsis
#include <string.h>

size_t strpbrk (char * s1 , char * s2 );

Description

The strpbrk function locates the first occurrence in the string pointed to by s1 of any character from the string pointed to by s2.

Returns

The strpbrk function returns a pointer to the character, or a null pointer if no character from s2 occurs in s1.

Implementation Notes

None.

11.5.5. The strrchr function

Synopsis
#include <string.h>

char *strrchr (char * s , int c );

Description

The strrchr function locates the last occurrence of c (converted to char) in the string pointed to by s. The terminating null character is considered to be part of the string.

Returns

The strrchr function returns a pointer to the located character, or a null pointer if the character does not occur in the string.

Implementation Notes

None.

11.5.6. The strspn function

Synopsis
#include <string.h>

size_t strspn (const char * s1 , const char * s2 );

Description

The strspn function computes the length of the maximum initial segment of the string pointed to by s1 which consists entirely of characters from the string pointed to by s2.

Returns

The strspn function returns the length of the segment.

See Also

Section 11.5.3

Implementation Notes

None.

11.5.7. The strstr function

Synopsis
#include <string.h>

char *strstr (char * s1 , const char * s2 );

Description

The strstr function locates the first occurrence in the string pointed to by s1 of the sequence of characters (excluding the terminating null character) in the string pointed to by s2.

Returns

The strstr function returns a pointer to the located string, or a null pointer if the string is not found. If s2 points to a string with zero length, the function returns s1.

Implementation Notes

None.

11.5.8. The strtok function

Synopsis
#include <string.h>

char *strtok (char * s1 , const char * s2 );

Description

A sequence of calls to the strtok function breaks the string pointed to by s1 into a sequence of tokens, each of which is delimited by a character from the string pointed to by s2. The first call in the sequence has s1 as its first argument, and is followed by calls with a null pointer as their first argument. The separator string pointed to by s2 may be different from call to call.

Returns

The strtok function returns a pointer to the first character of a token, or a null pointer if there is no token.

Implementation Notes

None.