[Previous] [Contents] [Next]

strspn()

Find one string inside another

Synopsis:

#include <string.h>

size_t strspn( const char* str,
               const char* charset );

Library:

libc

Description:

The strspn() function computes the length of the initial segment of the string pointed to by str that consists of characters from the string pointed to by charset. The terminating null character is not considered to be part of charset.

Returns:

The length of the segment.

Examples:

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

int main( void )
  {
    printf( "%d\n", strspn( "out to lunch", "aeiou" ) );
    printf( "%d\n", strspn( "out to lunch", "xyz" ) );
    return EXIT_SUCCESS;
  }

produces the output:

2
0

Classification:

ANSI

Safety:
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

strcspn()


[Previous] [Contents] [Next]