summaryrefslogtreecommitdiff
path: root/reference/C/EXAMPLES/strcmp.c
blob: ba36a6a0a3ef4e3b7e3bef499e5a26a1700ee3a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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);
}