Function name: strspn
Header file : <string.h>
Function prototype : int strspn(char *str1, char *str2);
Function : Calculate how many consecutive characters in the string str1 belong to the string str2. Calculate the consecutive characters from the beginning of the parameter str1 string, and these characters are all characters in the string pointed by str2. To put it simply, if the returned value is n, it means that n consecutive characters at the beginning of string str1 are all characters in string str2.
Parameters : char *str1 -- the string to be retrieved.
char *str2 -- This string contains the list of characters to be matched in str1.
Return value : Returns the number of characters in the string str2 that are consecutively included in the beginning of the string str1. Therefore, if the characters contained in str1 belong to str2, then the length of str1 is returned; if the first character of str1 does not belong to str2, then 0 is returned.
Program example: Calculate how many characters in string1 and string2 are in the array string str2, and output the result
#include<string.h>#include<stdio.h>intmain(void){char*string1=1234567890;char*string2=123DC8;intlength=strspn(string1,string2);printf(Characterwherestringsdifferisatposition%dn,length) ;return0;}
Running results:
Characterwherestringsdifferisatposition3