strspn() in C

CProgrammingServer Side Programming

The function strspn() is used to calculate the length of substring of first string which is present in second string. It returns the length of that substring.

Here is the syntax of strspn() in C language,

size_t strspn(const char *string1, const char *string2);

Here is an example of strspn() in C language,

Example

 Live Demo

#include <stdio.h>
#include<string.h>
int main() {
   const char s1[] = "Helloworld!";
   const char s2[] = "Hello";
   int length = strspn(s1, s2);
   printf("The length of string : %d", length);
   return 0;
}

Output

The length of string : 5
raja
Published on 08-Oct-2018 11:45:05
Advertisements