Function Strcmp

#include<stdio.h>
main()
{
char blog1[50],blog2[50];
printf("Enter string 1.\n");
scanf("%s",blog1);
printf("Enter string 2.\n");
scanf("%s",blog2);

printf("Strcmp Output - %d",strcmp(blog1,blog2));
// This compares the string stored in blog1 with string stored in blog2
// If ASCII value of 1st element of Blog1 is greater than AScii value of 1st element of Blog2
// then 1 is printed, in vice versa case we get -1
// And if both have the same ascii value it moves to checking of ASCII value of 2nd element stored
// in both, if all values come out to be equal then it returns 0.
}

 

OUTPUT [Click to enlarge]:

3 Cases:

 

1st Case [When both are same strings]:

Case 1

 

2nd Case [When ASCII value of 1st string is greater than ASCII value of 2nd string]:

Case 2

 

3rd Case [When ASCII value of 1st string is smaller than ASCII value of 2nd string]:

Case 3

Leave a Reply

Your email address will not be published.