C strcspn() Function

Last Updated:

C strcspn()

The strcspn() function scans str1 for the first occurrence of any of the characters that are part of str2, returning index value of the first matched character.

Example

C Compiler
#include <stdio.h> #include <string.h> int main() { long len; char str1[] = "wikimass.com"; char str2[] = "msk"; // k is the first match len = strcspn(str1, str2); printf("Index of first matched character: %ld", len); return 0; }

Syntax

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

Parameter Values

ValueTypeExplanation
str1 Required Specifies the string 1
str2 Required Specifies the string 2

Return Value

ValueExplanation
Number Returns the index value of the first matched character.

Share this Page

Meet the Author