codescracker


c

C strcspn()



« Previous Chapter Next Function »


strcspn()

The strcspn() function returns the length of the initial substring of the string pointed to by str1 that is made up of only those characters not contained in the string pointed to by str2. Stated differently, strcspn() returns the index of the first character in the string pointed to by str1 that matches any of the characters in the string pointed to by str2.

strcspn() Syntax

Following is the syntax of the strcspn() function :

#include<string.h>
size_t strcspn(const char *str1, const char *str2);

strcspn() Example

Following program prints the number 8 :

#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
	int len;
	len = strcspn("this is a test", "ab");
	printf("%d", len);
	getch();
}

« Previous Chapter Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test