X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstring%2Fstrcmp.c;h=874828eb269fc25a1082f5d41640cd45ed49e876;hp=17e138cdf2b989a389e385982112bbda9e6cd42f;hb=1d9d92ba957a0b8307c9a65c35867fde68e6533b;hpb=0a5395faab237ba9008352b0f4bee9659bbd3d5f diff --git a/functions/string/strcmp.c b/functions/string/strcmp.c index 17e138c..874828e 100644 --- a/functions/string/strcmp.c +++ b/functions/string/strcmp.c @@ -1,38 +1,16 @@ -// ---------------------------------------------------------------------------- -// $Id$ -// ---------------------------------------------------------------------------- -// Public Domain C Library - http://pdclib.sourceforge.net -// This code is Public Domain. Use, modify, and redistribute at will. -// ---------------------------------------------------------------------------- +/* ---------------------------------------------------------------------------- + * $Id$ + * ---------------------------------------------------------------------------- + * Public Domain C Library - http://pdclib.sourceforge.net + * This code is Public Domain. Use, modify, and redistribute at will. + * --------------------------------------------------------------------------*/ -int strcmp( const char * s1, const char * s2 ) { /* TODO */ }; - -/* Therx code -{ - while ((*s1 != '\0') && (*s1 == *s2)) - { - s1++; - s2++; - } - return (*(unsigned char *) s1) - (*(unsigned char *) s2); -} -*/ - -/* PDPC code - unreviewed +int strcmp( const char * src_1, const char * src_2 ) { - const unsigned char *p1; - const unsigned char *p2; - - p1 = (const unsigned char *)s1; - p2 = (const unsigned char *)s2; - while (*p1 != '\0') + while ( ( *src_1 != '\0' ) && ( *src_1 == *src_2 ) ) { - if (*p1 < *p2) return (-1); - else if (*p1 > *p2) return (1); - p1++; - p2++; + ++src_1; + ++src_2; } - if (*p2 == '\0') return (0); - else return (-1); + return ( *src_1 - *src_2 ); } -*/