Searching string with strspn() - C String

C examples for String:String Function

Description

Searching string with strspn()

Demo Code

#include <stdio.h>
#include <string.h>

int main( void )
{
    char  buf1[80], buf2[80];
    size_t loc;/*from w w  w  .  j av  a 2s  . c om*/

    printf("Enter the string to be searched: ");
    gets_s(buf1);
    printf("Enter the string containing target characters: ");
    gets_s(buf2);

    /* Perform the search. */

    loc = strspn(buf1, buf2);

    if ( loc ==  0 )
        printf("No match was found.\n");
    else
        printf("Characters match up to position %d.\n", loc-1);
    return 0;
}

Result


Related Tutorials