C Programming/C Reference/nonstandard/strcasecmp

In programming language C, strcasecmp is a function declared in the strings.h header file (or sometimes in string.h) that compares two strings irrespective of the case of characters.

This function is in POSIX.1-2001.

Prototype edit

int strcasecmp(const char *f1, const char *f2);


This function returns an integer i :
i > 0, if lowercase(f1) is greater than lowercase(f2)
i < 0, if lowercase(f1) is found less than string lowercase(f2) and
i = 0, if lowercase(f1) is equal to lowercase(f2).

Example edit

# include <stdio.h>
# include <strings.h>
int main(int argc, char *argv[]){

    int i;
    if(argc != 3){
        printf("bad input\n");
        return 1;
    }
    i = strcasecmp(argv[1], argv[2]);
    if (i == 0)
        printf("'%s' equals '%s'\n", argv[1], argv[2]);
    else if (i > 0)
        printf("'%s' is greater than '%s'\n", argv[1], argv[2]);
    else if (i < 0)
        printf("'%s' is less than '%s'\n", argv[1], argv[2]);
    return 0;
}