strcspn - C string.h

C examples for string.h:strcspn

Type

function

From

<cstring> 
<string.h>

Description

Scans str1 for the first occurrence of any of the characters in str2

Prototype

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

Parameters

Parameter Description
str1 C string to be scanned.
str2 C string containing the characters to match.

Return value

The length of the initial part of str1 not containing any of the characters that are part of str2.

Example

Demo Code

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

int main ()/*from w ww . j  a va2  s  .co m*/
{
  char str[] = "this is a test test73 test test test";
  char keys[] = "1234567890";
  int i;
  i = strcspn (str,keys);
  printf ("The first number in str is at position %d.\n",i+1);
  return 0;
}

Related Tutorials