X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstring%2Fstrchr.c;h=8c6e8a42ffec9099a401ea11f79c5edb04d9dd80;hp=960e7e4ed599fd9070b13007969ea5485464831e;hb=da0f3f353d417fed71f358a48d5d5394145e460d;hpb=1d9d92ba957a0b8307c9a65c35867fde68e6533b diff --git a/functions/string/strchr.c b/functions/string/strchr.c index 960e7e4..8c6e8a4 100644 --- a/functions/string/strchr.c +++ b/functions/string/strchr.c @@ -1,21 +1,38 @@ -/* ---------------------------------------------------------------------------- - * $Id$ - * ---------------------------------------------------------------------------- - * Public Domain C Library - http://pdclib.sourceforge.net - * This code is Public Domain. Use, modify, and redistribute at will. - * --------------------------------------------------------------------------*/ +/* strchr( const char *, int ) -#include <__NULL.h> + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ -char * strchr( const char * src, int c ) +#include + +#ifndef REGTEST + +char * strchr( const char * s, int c ) { - while ( *src != '\0' ) + do { - if ( *src == (const char) c ) + if ( *s == (char) c ) { - return (char *) src; + return (char *) s; } - ++src; - } + } while ( *s++ ); return NULL; } + +#endif + +#ifdef TEST +#include "_PDCLIB_test.h" + +int main( void ) +{ + char abccd[] = "abccd"; + TESTCASE( strchr( abccd, 'x' ) == NULL ); + TESTCASE( strchr( abccd, 'a' ) == &abccd[0] ); + TESTCASE( strchr( abccd, 'd' ) == &abccd[4] ); + TESTCASE( strchr( abccd, '\0' ) == &abccd[5] ); + TESTCASE( strchr( abccd, 'c' ) == &abccd[2] ); + return TEST_RESULTS; +} +#endif