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 - <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

 unsigned int  strcspn(string1,charset);
 char          *string1;                 Source string
 char          *charset;                 Character set

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

    Returns:    The index of the first character in 'string1' that
                belongs to the set of characters found in 'charset'.
                This value equals the length of the first substring of
                'string1' that is made up of characters not in 'charset'.
                If 'string1' begins with a character in 'string2',
                strcspn() returns 0.

      Notes:    strcspn() expects to operate on null-terminated strings.
                No overflow checking is done when strings are copied or
                appended.

  -------------------------------- 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