#include <lcstring.h> size_t strrcspn(const char *str, const char *cset);
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
.
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.
#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'); }
strcspn
, strrchr
, strrspn
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.