UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to study strcmp() function

C program to study strcmp() function

by Krishna


Posted on 27 Jun 2018 Category: C Views: 1833


C program to study strcmp() function

strcmp( ) function in C compares two given strings and returns zero if they are sameIf length of string1 < string2, it returns < 0 value. If length of string1 > string2, it returns > 0 value. Syntax for strcmp( ) function is given below.

int strcmp ( const char * str1, const char * str2 )

strcmp( ) function is case sensitive. i.e, “A” and “a” are treated as different characters.

#include<string.h>

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

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

OUTPUT



Leave a Comment:


Click here to register

Popular articles