How to get the length of the first characters of str1 that not include in str2 in C

1 Answer

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

// size_t strcspn ( const char * str1, const char * str2 );

// Scan s1 for the first occurrence of any of the characters that are in s2
// return the number of characters read in s1 before the first occurrence

int main(void) 
{
    char s1[] = "python c c++";
    char s2[] = "java c#";
   
    int i = strcspn(s1, s2); // (space)
    printf ("First characters from s1 that not include in s2: %d\n", i);
    
    return 0;
}
   
/*
run:

First characters from s1 that not include in s2: 6

*/

 



answered Aug 8, 2017 by avibootz
...