Function name : strcspn
Header file : <string.h>
Function prototype : int strcspn(char *str1, char *str2);
Function : Search the string str1 in sequence for several consecutive characters that do not belong to the 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: If there is no matching character in str2, the length of str1 is returned. Otherwise, the number of consecutive characters at the beginning of string str1 that are different from all characters in string str2 is returned.
Note : Count consecutive characters from the beginning of string str1, and these characters are not in string str2 at all. Simply put, if the returned value is n, it means that there are n consecutive characters at the beginning of string str1 that do not contain the characters in string str2.
Program example: Find the number of characters in string1 that do not match the characters in string2 and output the result
#include<string.h>#include<stdio.h>intmain(void){char*string1=1234567890;char*string2=747DC8;intlength=strcspn(string1,string2);printf(Characterwherestringsintersectisatposition%dn,length) ;return0;}
Running results:
Characterwherestringsintersectisatposition3