C Program Of Strcmp() Function

C Program Of Strcmp() Function

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

main()
{

char str1[20];
char str2[20];

int i;

printf("Enter string1:\n");
scanf("%s",str1);

printf("Enter string2:\n");
scanf("%s",str2);

i=strcmp(str1,str2);     //string checked character by character..by there ascii value...if ascii value is greater like 'a' ascii value is less than 'b' so string also least.

if(i<0)
{

printf("str1 < str2\n");

}

else if(i>0)
{

printf("str1 > str2\n");

}

else if(i==0)
{

printf("str1 = str2\n");

}
}

Related Posts