The strcspn () function in C
The function size_t strcspn (const char * str1, const char * str2) calculates the length of the character segment of string str1 without containing the characters in str2.
The function size_t strcspn (const char * str1, const char * str2) calculates the length of the character segment of string str1 without containing the characters in str2.
Declare the strcspn () function in C
Here is the declaration for strcspn () in C:
size_t strcspn ( const char * str1 , const char * str2 )
Parameters
str1 - This is a string of characters to be scanned.
str2 - String contains a list of characters to match in str1.
Returns the value
This function returns the number of characters in a string segment of the original string str1 that is not in the str2 string.
For example
The following C program illustrates the usage of strcspn () in C:
#include #include int main () { int len ; const char str1 [] = "ABCDEF4960910" ; const char str2 [] = "013" ; len = strcspn ( str1 , str2 ); printf ( "Ky tu ket noi dau tien tai vi tri %dn" , len + 1 ); return ( 0 ); }
Compiling and running the above C program will result:
According to Tutorialspoint
Previous article: Function strncpy () in C
Next lesson: strerror () function in C
You should read it
- The strlen () function in C
- The strchr () function in C
- The strerror () function in C
- Strncat () function in C
- The strncpy () function in C
- Memset () function in C
- How to 'survive' with the stress of learning programming
- Bookmark a few tricks to help you master a programming language
- The strrchr () function in C
- Top 20 free programming learning websites need to bookmark immediately!
- Beginners of computer programming need to focus on what?
- Strcpy () function in C
Maybe you are interested
Nvidia just caused the 'blue screen of death' error for Windows Admire incredibly detailed images of the Orion Nebula through the eyes of the James Webb telescope This star 'tears up' its companion to create a rare beautiful nebula Admire the moment millions of new stars are born in the Lupus 3 nebula Before 'returning to Thanos', what was the fate and appearance of Nebula in the comics? How to create a blue screen of death (BSOD) to 'prank' friends