C Programming
Computer Programming

C program to comparison limited characters during the function call using strncmp() function



Write a program in C to comparison is limited to the number of characters specified during the function call using strncmp() function

\* C program to comparison limited characters during the function call using strncmp() function *\

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

char str1[100], str2[100] ;
int result, n ;
printf ("\n Enter the first string : ") ;
scanf( "%s", str1 ) ;
printf ("\n Enter the second string : ") ;
scanf("%s", str2 ) ;
printf ("\n Enter the number of characters that needs to be compared : ") ;
scanf("%d", &n ) ;
result = strncmp( str1, str2, n ) ;

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

}

Output of Program :

Output of C program to comparison limited characters during the function call using strncmp() function