]> pd.if.org Git - pdclib/blob - functions/string/strrchr.c
527065baaab25f612d3674c5998071a6bbd16230
[pdclib] / functions / string / strrchr.c
1 /* $Id$ */
2
3 /* strrchr( const char *, int c )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <string.h>
10
11 #ifndef REGTEST
12
13 char * strrchr( const char * s, int c )
14 {
15     size_t i = 0;
16     while ( s[i++] );
17     do
18     {
19         if ( s[--i] == (char) c )
20         {
21             return (char *) s + i;
22         }
23     } while ( i );
24     return NULL;
25 }
26
27 #endif
28
29 #ifdef TEST
30 #include <_PDCLIB_test.h>
31
32 int main( void )
33 {
34     char abccd[] = "abccd";
35     TESTCASE( strrchr( abcde, '\0' ) == &abcde[5] );
36     TESTCASE( strrchr( abcde, 'e' ) == &abcde[4] );
37     TESTCASE( strrchr( abcde, 'a' ) == &abcde[0] );
38     TESTCASE( strrchr( abccd, 'c' ) == &abccd[3] );
39     return TEST_RESULTS;
40 }
41 #endif