Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>strcspn() scan one string for another</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 strcspn()               Scan One String for Another

 #include   <string.h>                   Required for declarations only

 size_t  strcspn(string1,charset);
 const char *string1;                    Source string
 const char *charset;                    Character set

    strcspn() searches 'string1' for the first occurrence of any of the
    characters in 'charset'.  The null character that terminates the
    string is not considered in the search.

    Returns:    The index of the first character in 'string1' belonging
                to the set of characters in 'charset'.  This value is the
                length of the first substring of 'string1' consisting of
                characters not in 'charset'.  If the first character in
                'string1' is a character in 'charset', strcspn() returns
                0.

      Notes:    strcspn() expects to operate on null-terminated strings.

   -------------------------------- Example ---------------------------------

    This example gets the length of the string up to the first delimiter
    defined in the string 'delim'.

           #include <string.h>

           char string[35] = "Pick up the sword. Run for cover.";
           char delim[3] = ".!?";
           int rslt;

           main()
           {
                 rslt = strcspn(string,delim);
                 printf("%c \n",string[rslt]);
           }



See Also: strstr() strspn()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson