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,

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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 24-Jun-2020

114 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements