strcspn() - String Manipulation Function

How to perform string complement span in C++?


strcspn() manipulation function returns the index of the first character in the str1 that matches any of the characters in str2 by complement span.


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

Example :

#include <stdio.h>
#include <cstring.h>
int main ()
char str1[] = "i got 2nd rank in the class";
char str2[] = "1234567890";
int j;
j = strcspn (str1,str2);
printf ("Occurence of a number in
str1 is at %dth position.\n",j+1);
return 0;

Result :

Occurence of a number in str1 is at 7th position.

In the above example, "strcspn()" manipulation function is used find index of appearance of any one integer contained in "str2" in "str1" through complement span.

C++ Tutorial

Ask Questions

Ask Question