C Programming
Computer Programming

C program to compares two strings and returns an integer value using strcmp() function



Write a program in C to compares two strings and returns an integer value based on the result using strcmp() function

\* C program to compares two strings and returns an integer value using strcmp() function *\

# include < stdio.h >
# include < string.h >
int   main( )
{

char str1[100], str2[100] ;
int result ;
printf ("\n Enter the first string : ") ;
scanf("%s", str1 ) ;
printf ("\n Enter the second string : ") ;
scanf("%s", str2 ) ;
result = strcmp( str1, str2 ) ;

if( result > 0 )
{
      printf("\n first string is (alphabetically) greater than second string !") ;
}
else if( result < 0 )
{
      printf("\n first srting is (alphabetically) less than second string !") ;
}
else
{
      printf("\n Both the strings are equal !") ;
}

return 0;

}

Output of Program :

Output of C program to compares two strings and returns an integer value using strcmp() function