
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C library function - strspn()
Description
The C library function size_t strspn(const char *str1, const char *str2) calculates the length of the initial segment of str1 which consists entirely of characters in str2.
Declaration
Following is the declaration for strspn() function.
size_t strspn(const char *str1, const char *str2)
Parameters
str1 − This is the main C string to be scanned.
str2 − This is the string containing the list of characters to match in str1.
Return Value
This function returns the number of characters in the initial segment of str1 which consist only of characters from str2.
Example
The following example shows the usage of strspn() function.
#include <stdio.h> #include <string.h> int main () { int len; const char str1[] = "ABCDEFG019874"; const char str2[] = "ABCD"; len = strspn(str1, str2); printf("Length of initial segment matching %d\n", len ); return(0); }
Let us compile and run the above program that will produce the following result −
Length of initial segment matching 4
string_h.htm
Advertisements