X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fstrchr.c;h=96ab0519aafbbdc8f4be004cf77929fabfc1914c;hb=8f2e7cffffecca3d7c937be102fcf9d5ec17241c;hp=dcfc025e8cd4bec4ed62e9c548710914b2ae7929;hpb=e5456e3c2697c4e17fc9aa3439f2e305517b4d96;p=pdclib.old diff --git a/functions/string/strchr.c b/functions/string/strchr.c index dcfc025..96ab051 100644 --- a/functions/string/strchr.c +++ b/functions/string/strchr.c @@ -1,28 +1,39 @@ -// ---------------------------------------------------------------------------- -// $Id$ -// ---------------------------------------------------------------------------- -// Public Domain C Library - http://pdclib.sourceforge.net -// This code is Public Domain. Use, modify, and redistribute at will. -// ---------------------------------------------------------------------------- +/* $Id$ */ -// ---------------------------------------------------------------------------- -// C++ +/* Release $Name$ */ -const char * strchr( const char * s, int c ) { /* TODO */ }; -char * strchr( char * s, int c ) { /* TODO */ }; +/* strchr( const char *, int ) -// ---------------------------------------------------------------------------- -// Standard C + 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 * s, int c ) { /* TODO */ }; +#include -/* PDPC code - unreviewed +char * strchr( const char * s, int c ) { - while (*s != '\0') + do { - if (*s == (char)c) return ((char *)s); - s++; - } - return (NULL); + if ( *s == (char) c ) + { + return (char *) s; + } + } while ( *s++ ); + return NULL; } -*/ + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main() +{ + char abccd[] = "abccd"; + BEGIN_TESTS; + 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