Jump to content

Strcspn

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Asmita yendralwar (talk | contribs) at 08:17, 14 October 2011. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

strcspn is the function from c standard library (header file string.h).

It search the string for certain set of characters.

The strcspn() function calculates the length of initial segment of string1 which does not contain any character from sting2.

Return Value

This function returns the index of first character in string1 that matches with any character of string2.

Syntax

#include <string.h>

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

Example

<source lang="c"> #include <stdio.h>

#include <string.h>

int main()

{

char s[20] = "wikireader007", t[11] = "0123456789";

printf("The first decimal digit of s is at position: %d.\n", strcspn(s, t));

return 0;

}

Output:

The first decimal digit of s is at position: 10

See also

References