Finding the first character in a string that does not belong to a set of characters using strspn() C function
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows 2003 Server Standard Edition
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)
Other info:
To do: Finding the first character in a string that does not belong to a set of characters using strspn() C function
To show: How to use the strspn() C function to return the index of the first character in a string that does not belong to a set of characters
// Using strspn()/wcsspn()/_mbsspn()
#include <stdio.h>
#include <string.h>
int main(void)
{
char *string1 = "The initial value is 3.14159";
char *string2 = "aehilsTuv";
printf(" Using strspn()\n");
printf(" ---------------\n");
printf("string1 = %s\n", string1);
printf("string2 = %s\n", string2);
printf("\nThe length of the initial segment of string1\n");
printf("containing only characters from string2 is = %u\n", strspn(string1, string2));
return 0;
}
Output example:
Using strspn()
---------------
string1 = The initial value is 3.14159
string2 = aehilsTuv
The length of the initial segment of string1
containing only characters from string2 is = 3
Press any key to continue . . .