X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstring%2Fstrstr.c;h=4587c68c6e2d5f107b5eeedfc506763d42a6cb09;hb=c0169638bd02098717cb23fbbca3bcc4e4caccf0;hp=b2494234b23df4944ef119071c7e04ed40e3be8f;hpb=34893ecc2200dc7017c36a54cb6c5f4c2378b5ec;p=pdclib diff --git a/functions/string/strstr.c b/functions/string/strstr.c index b249423..4587c68 100644 --- a/functions/string/strstr.c +++ b/functions/string/strstr.c @@ -1,17 +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 + +char * strstr( const char * s1, const char * s2 ) +{ + const char * p1 = s1; + const char * p2; + while ( *s1 ) + { + p2 = s2; + while ( *p2 && ( *p1 == *p2 ) ) + { + ++p1; + ++p2; + } + if ( ! *p2 ) + { + return (char *) s1; + } + ++s1; + p1 = s1; + } + return NULL; +} + +#warning Test driver missing.