span the complement of a string

You're viewing an older version of this page (#3500). View the current version.

View versions (3)

NAME

<span class="Nm" id="strcspn">strcspn</span>

INTERFACE

#include <string.h> size_t strcspn ( const char *s, const char *charset )

DESCRIPTION

The strcspn function spans the initial part of the null-terminated string &#92;c s as long as the characters from &#92;c s do not occur in string &#92;c charset (it spans the <span class="Em">complement</span> of &#92;c charset).

Example 1

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

int main()
{
  char s[20] = "abcde1010101", t[3] = "01";
  printf("The first binary digit of s is at position: %d.\n", strcspn(s, t));
  return 0;
}

Output:

The first binary digit of s is at position: 5.

RETURN VALUES

The strcspn function returns the number of characters spanned.

SEE ALSO

memchr, strchr, strpbrk, strrchr, strspn, strstr, strtok

STANDARDS

The strcspn function conforms to ISO/IEC 9899:1990 ("ISO C90").