strcspn() — Compare strings
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
Format
#include <string.h>
size_t strcspn(const char *string1, const char *string2);
General description
Computes the length of the initial portion of the string pointed to by string1 that contains no characters from the string pointed to by string2.
Returned value
strcspn() returns the calculated length of the initial portion found.
Example
CELEBS39
/* CELEBS39
This example uses &strcspn. to find the first occurrence of
any of the characters a, x, l or e in string.
*/
#include <stdio.h>
#include <string.h>
#define SIZE 40
int main(void)
{
char string[ SIZE ] = "This is the source string";
char * substring = "axle";
printf( "The first %i characters in the string \"%s\"\
are not in the " "string \"%s\" \n",
strcspn(string, substring), string, substring);
}
Output
The first 10 characters in the string "This is the source string"
are not in the string "axle"