C strspn function returns the index of difference between two strings

Syntax

C strspn function has the following format.

size_t strspn(const char *str1, const char *str2);

C strspn function is from header file string.h.

Description

C strspn function returns the index of the first character in *str1 that does not match any of the characters in *str2.

Example

Use C strspn function to find out the difference.


#include <string.h>
#include <stdio.h>
int main(void)
{// w w w . j a va 2 s  .com
  int len;

  len = strspn("this is a test", "hi");
  printf("%d", len);

  return 0;
}

The code above generates the following result.





















Home »
  C Language »
    Function Reference »




assert.h
ctype.h
math.h
setjmp.h
signal.h
stdio.h
stdlib.h
string.h
time.h
wctype.h