beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

C strspn() Function

By Chaitanya Singh | Filed Under: C library functions

The function strspn() searches specified string in the given string and returns the number of the characters that are matched in the given string.

C strspn() declaration

size_t strspn(const char *str1, const char *str2)

str1 – The string in which the characters of string str2 are searched.
str2 – Another string, the characters of this string are searched in str1.

Return value of strspn()

It returns the count of the characters that are matched in the given string.

Example: strspn() function

#include <stdio.h>
#include <string.h>
int main () {
   int len; 
   const char str1[] = "abcdefgh"; 
   const char str2[] = "abXXcdeZZh";
   /* Searching the string str2 in the string str1.
    * It returns the count of characters of str2 that
    * are matched in the str1 
    */
   len = strspn(str1, str2);
   printf("Number of matched characters: %d\n", len );
   return 0;
}

Output:

Number of matched characters: 5

Related Posts:

  1. C – strrchr() function
  2. C – strncpy() function
  3. C – strcoll() function
  4. C – strcmp() function

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

C Programming Tutorial

  • Turbo C++ installation
  • First C Program
  • C - Keywords
  • Operator precedence
  • C - if statement
  • C - if..else
  • C - for loop
  • C - while loop
  • C - do while loop
  • C - continue
  • C - break statement
  • C - switch..case
  • C - goto statement
  • C - Arrays
  • 2 D array
  • C - String
  • C - functions
  • Function call by reference
  • Function call by value
  • Array to function
  • C - Structures
  • C - Pointers
  • Pointer to Pointer
  • Pointers to functions
  • C - function pointers
  • Pointer & Array
  • C - File I/O
  • C Programming Examples

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap