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