strspn() in C

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,


 Live Demo

#include <stdio.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;


The length of string : 5
Samual Sam
Samual Sam

Learning faster. Every day.