X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstring%2Fstrcmp.c;h=e72e3761bf78a260f77e4037f8a81580c0e2abe8;hp=17e138cdf2b989a389e385982112bbda9e6cd42f;hb=419762f3c5da2a601e3c7427e25ae01293a73223;hpb=714f97432fcfa2122e21fd3cf184d49a213a180c diff --git a/functions/string/strcmp.c b/functions/string/strcmp.c index 17e138c..e72e376 100644 --- a/functions/string/strcmp.c +++ b/functions/string/strcmp.c @@ -5,34 +5,12 @@ // 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 ); } -*/