strrcspn -- Locate the Last Character in a Set

SYNOPSIS

 #include <lcstring.h>

 size_t strrcspn(const char *str, const char *cset);
 

DESCRIPTION

strrcspn scans the input string (str) for the last occurrence of any character in the search set (cset). The strrcspn function is the reverse of strcspn.

RETURN VALUE

strrcspn returns the number of characters in the argument string up to and including the last occurrence of any character in the search set.

If no character in the search set can be found in the input string, the value returned is 0. If the search set is null (that is, if it contains no characters), the return value from strrcspn is the length of the input string.

CAUTION

A protection or addressing exception may occur if either argument is not terminated with the null character.

EXAMPLE

  #include <lcstring.h>
  #include <stdio.h>

  void main()
  {
     char *text, input[80];
     size_t len;
     int i;

     puts("Enter a line of text:");
     text = gets(input);

        /* Find the last blank space or punctuation */
        /*  character in a line terminated by '0'. */
     len = strrcspn(text, ",."?;':!");

        /* Write to stdout all text after the last  */
        /*  punctuation character or space in the   */
        /*  string (which might not be a word).     */
     for(i = len; text[i] != '0' && text[i] != 'n'; i++)
        putchar(text[i]);
     putchar('n');
  }

 

RELATED FUNCTIONS

strcspn, strrchr, strrspn

SEE ALSO

String Utility Functions

Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.