Jump to content

Strcspn: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
Line 26: Line 26:
{
{


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


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


The first decimal digit of s is at position: 7
The first decimal digit of s is at position: 10





Revision as of 06:51, 4 October 2011

strcspn

This is the function from 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 sting.

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

#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