Write a program that reads two strings CH1 and CH2, compares them lexicographically and displays the result using strcmp:
Example:
Enter the first string : ABC
Enter the second string: abc
"ABC" precedes "abc"
Difficulty level

Video recording
This exercise is mostly suitable for students
#include<stdio.h>
#include<string.h>
#include<conio.h>
#define SIZE 50
void main()
{
char CH1[SIZE], CH2[SIZE];
printf("Enter the first string : ");
scanf("%s", CH1);
printf("Enter the second string : ");
scanf("%s", CH2);
if (strcmp(CH1, CH2) == 0)
printf("\"%s\" is equal to \"%s\"\n", CH1, CH2);
else
if (strcmp(CH1, CH2) < 0)
printf("\"%s\" precedes \"%s\"\n", CH1, CH2);
else
printf("\"%s\" precedes \"%s\"\n", CH2, CH1);
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
