C Programming
Computer Programming

C program to scans the string and returns the number of characters on first matched using strcspn() function



Write a program in C to scans the main string for the given string and returns the number of characters in the main string from beginning till the first matched character is found using strcspn() function

\* C program to scans the string and returns the number of characters on first matched using strcspn() function *\

# include < stdio.h >
# include < string.h >
int   main( )
{

char str[100] ;
char searchString[10] ;
int loc ;
printf ("\n Enter a string : " ) ;
scanf("%s", str ) ;
printf("\n Enter a Characher for Search : ") ;
scanf("%s", &searchString ) ;
loc = strcspn( str, searchString ) ;
printf("\n The first matched char in string is at: %d", (loc+1) ) ;
return 0 ;

}

Output of Program :

Output of C program to scans the string and returns the number of characters on first matched using strcspn() function