]> pd.if.org Git - pdclib/blob - functions/string/strchr.c
PDCLib includes with quotes, not <>.
[pdclib] / functions / string / strchr.c
1 /* strchr( const char *, int )
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 * strchr( const char * s, int c )
12 {
13     do
14     {
15         if ( *s == (char) c )
16         {
17             return (char *) s;
18         }
19     } while ( *s++ );
20     return NULL;
21 }
22
23 #endif
24
25 #ifdef TEST
26 #include "_PDCLIB_test.h"
27
28 int main( void )
29 {
30     char abccd[] = "abccd";
31     TESTCASE( strchr( abccd, 'x' ) == NULL );
32     TESTCASE( strchr( abccd, 'a' ) == &abccd[0] );
33     TESTCASE( strchr( abccd, 'd' ) == &abccd[4] );
34     TESTCASE( strchr( abccd, '\0' ) == &abccd[5] );
35     TESTCASE( strchr( abccd, 'c' ) == &abccd[2] );
36     return TEST_RESULTS;
37 }
38 #endif