C Standard Libraries C++

strcspn()

Declaration

size_t strcspn(const char* kcpString, const char* kcpChars);

Description

This function returns the index of the first occurrence of one of the chars in the null- terminated set "kcpChars" inside the null-terminated string "kcpString." If no occurrence is found, the function returns NULL.

Example

#include <cstdio>
#include <cstring>

int main()
{
    char caString[] = "XoaX.net";
    char caChars[] = "aei";
    // Find the first of "aei" inside of "XoaX.net"
    int iFound = strcspn(caString, caChars);
    printf("First of %s found at %i\n", caChars, iFound);

    return 0;
}

Output

strcspn() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.