C Compare String

C Compare String


a) When string1 is greater than string2, it returns positive value.
b) When string1 is lesser than string2, it returns negative value.

Syntax:

int strcmp (const char *s1, const char *s2);

Program:

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

int main()
{
    char a[100], b[100];    
    printf("Enter the first string\n");    
    gets(a);    

    printf("Enter the second string\n");    
    gets(b);
    
    if( strcmp(a,b) == 0 )
        printf("Entered strings are equal.\n");
    else
        printf("Entered strings are not equal.\n");
        return 0;
}

Program Output:

compare-strings-c

Explanation: