]> pd.if.org Git - pdclib/blob - functions/string/strcmp.c
Removed the $Name$ tags (not supported by SVN). Added $Id$ to Makefile / text files.
[pdclib] / functions / string / strcmp.c
1 /* $Id$ */
2
3 /* strcmp( const char *, const char * )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <string.h>
10
11 #ifndef REGTEST
12
13 int strcmp( const char * s1, const char * s2 )
14 {
15     while ( ( *s1 ) && ( *s1 == *s2 ) )
16     {
17         ++s1;
18         ++s2;
19     }
20     return ( *s1 - *s2 );
21 }
22
23 #endif
24
25 #ifdef TEST
26 #include <_PDCLIB_test.h>
27
28 int main( void )
29 {
30     char cmpabcde[] = "abcde";
31     char empty[] = "";
32     TESTCASE( strcmp( abcde, cmpabcde ) == 0 );
33     TESTCASE( strcmp( abcde, abcdx ) < 0 );
34     TESTCASE( strcmp( abcdx, abcde ) > 0 );
35     TESTCASE( strcmp( empty, abcde ) < 0 );
36     TESTCASE( strcmp( abcde, empty ) > 0 );
37     return TEST_RESULTS;
38 }
39 #endif