X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fstrstr.c;h=4587c68c6e2d5f107b5eeedfc506763d42a6cb09;hb=c0169638bd02098717cb23fbbca3bcc4e4caccf0;hp=a1f8b74b329c428f1e825acfdaa568bda6c75c09;hpb=0a5395faab237ba9008352b0f4bee9659bbd3d5f;p=pdclib diff --git a/functions/string/strstr.c b/functions/string/strstr.c index a1f8b74..4587c68 100644 --- a/functions/string/strstr.c +++ b/functions/string/strstr.c @@ -1,39 +1,35 @@ -// ---------------------------------------------------------------------------- -// $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 * strstr( const char * s1, const char * s2 ) { /* TODO */ }; -char * strstr( char * s1, const char * s2 ) { /* TODO */ }; +/* strstr( const char *, const char * ) -// ---------------------------------------------------------------------------- -// 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 * strstr( const char * s1, const char * s2 ) { /* TODO */ }; +#include -/* PDPC code - unreviewed +char * strstr( const char * s1, const char * s2 ) { - const char *p = s1, *p1, *p2 = s2; - - while (*p) + const char * p1 = s1; + const char * p2; + while ( *s1 ) { - if (*p == *s2) + p2 = s2; + while ( *p2 && ( *p1 == *p2 ) ) + { + ++p1; + ++p2; + } + if ( ! *p2 ) { - p1 = p; - p2 = s2; - while ((*p2 != '\0') && (*p1++ == *p2++)) ; - if (*p2 == '\0') - { - return (char *)p; - } + return (char *) s1; } - p++; + ++s1; + p1 = s1; } return NULL; } -*/ + +#warning Test driver missing.