diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2008-01-27 11:37:44 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2008-01-27 11:37:44 +0100 |
commit | 7e0f021a9aec35fd8e6725e87e3313b101d26f5e (patch) | |
tree | b1cacc4b24393f517aeb4610e9e1021f954307a8 /reference/C/EXAMPLES/strcmp.c |
Initial import (2.0.2-6)2.0.2-6
Diffstat (limited to 'reference/C/EXAMPLES/strcmp.c')
-rw-r--r-- | reference/C/EXAMPLES/strcmp.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/reference/C/EXAMPLES/strcmp.c b/reference/C/EXAMPLES/strcmp.c new file mode 100644 index 0000000..ba36a6a --- /dev/null +++ b/reference/C/EXAMPLES/strcmp.c @@ -0,0 +1,57 @@ +/****************************************************************** + * + * Purpose: Program to demonstrate the use of strcmp. + * Date: 05-Dec-96 + * Author: M J Leslie. + * Descrip: The standard strcmp returns 0 when the strings match + * and indicates which string is lexigraphically greater. + * Every time I have used strcmp, I have never been interested + * in which string is greater and always frustrated that the + * return code is inverted. This function tidys things up. + * + ******************************************************************/ + +#include <string.h> +#include <stdio.h> + +#define TRUE 1 +#define FALSE 0 + +int StringCompare(char *s1, char *s2); + +main() +{ + char One[] = "Bartman"; + char Two[] = "Batman"; + + int Ret; + + Ret = StringCompare(One, Two); + + if (Ret == TRUE) + { + puts("The Strings match"); + } + else + { + puts("The Strings do not match"); + } +} + +/**************************************************************/ + +int StringCompare(char *s1, char *s2) +{ + int Ret; + + if (strcmp(s1, s2)) + { + Ret = 0; + } + else + { + Ret = 1; + } + + return (Ret); +} |