Apr 4, 2012

C Program to demonstrate strspn function.

Write a C Program to demonstrate strspn function.
The strspn() function returns the index of the first character in string1 that doesn't match any character in string2. If all the characters of the string2 matched with the string1, strspn returns the length of the string1. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on  www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact info@c-program-example.com
* To find more C programs, do visit www.c-program-example.com
* and browse!
* 
*                      Happy Coding
***********************************************************/

#include<stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
    int spn;
    char str1[] = "1234hjbcde09i";
    char str2[] = "12345";
    char str3[] = "a12d3456fd";
    char char_list[] = "1234567890";
    clrscr();
    //It returns 4
    spn = strspn (str1,char_list);
    printf ("\n\nThe length of the initial numbers for str1 is %d.\n",spn);
    
    //It returns 5
    spn = strspn (str2,char_list);
    printf ("\nThe length of the initial numbers for str2 is %d.\n",spn);
    
    //It returns 0
    spn = strspn (string3,char_list);
    printf ("\nThe length of the initial numbers for string3 is %d.\n",spn);
    return 0;
}

Read more c programs
C Basic
C Strings
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it


(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!
To browse more C Programs visit this link