C programming string.h function - size_t strcspn(const char *str1, const char *str2)

www.ig‮c.aeditfi‬om

The strcspn function from the C string.h library returns the length of the initial segment of str1 which consists entirely of characters not in the string str2.

The function prototype is:

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

Here's an example usage of the strcspn function:

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

int main() {
    char str1[] = "abcde";
    char str2[] = "xyz";

    size_t len = strcspn(str1, str2);

    printf("Length of initial segment without chars from str2: %zu\n", len);
    return 0;
}

This will output:

Length of initial segment without chars from str2: 5