C programming string.h function - int strcmp(const char *str1, const char *str2)

The strcmp function is used to compare two null-terminated strings. It returns an integer that is negative, zero, or positive depending on whether the first string is less than, equal to, or greater than the second string.

The function has the following prototype:

int strcmp(const char *str1, const char *str2);
Sou‮i.www:ecr‬giftidea.com

where str1 and str2 are pointers to the null-terminated strings to be compared.

Here's an example usage of strcmp:

#include <stdio.h>
#include <string.h>

int main() {
    char str1[] = "hello";
    char str2[] = "world";
    int result = strcmp(str1, str2);

    if (result < 0) {
        printf("'%s' is less than '%s'\n", str1, str2);
    } else if (result > 0) {
        printf("'%s' is greater than '%s'\n", str1, str2);
    } else {
        printf("'%s' is equal to '%s'\n", str1, str2);
    }

    return 0;
}

This program outputs the following:

'hello' is less than 'world'