Compare two strings with C.
#include <stdio.h>
#include <string.h>
int main()
{
char str1[100], str2[100];
int res;
printf("Enter first string: ");
gets(str1);
printf("Enter second string: ");
gets(str2);
res = strcmp(str1, str2);
if (res == 0)
{
printf("Both strings are equal.");
}
else if (res == -1)
{
printf("First string is lexicographically smaller than second.");
}
else
{
printf("First string is lexicographically greater than second.");
}
return 0;
}
Output
Enter first string : Rezaul
Enter second string : Karim
First string is lexicographically greater than second.
0 Comments