]> pd.if.org Git - pdclib/blobdiff - functions/string/strchr.c
PDCLib includes with quotes, not <>.
[pdclib] / functions / string / strchr.c
index dcfc025e8cd4bec4ed62e9c548710914b2ae7929..8c6e8a42ffec9099a401ea11f79c5edb04d9dd80 100644 (file)
@@ -1,28 +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 )
 
-// ----------------------------------------------------------------------------
-// C++
-
-const char * strchr( const char * s, int c ) { /* TODO */ };
-char * strchr( char * s, int c ) { /* TODO */ };
+   This file is part of the Public Domain C Library (PDCLib).
+   Permission is granted to use, modify, and / or redistribute at will.
+*/
 
-// ----------------------------------------------------------------------------
-// Standard C
+#include <string.h>
 
-char * strchr( const char * s, int c ) { /* TODO */ };
+#ifndef REGTEST
 
-/* 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;
 }
-*/
+
+#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