About Lesson
Program to Compare Two Strings.
#include <stdio.h>
#include <string.h>// Function to compare two strings
int compareStrings(char str1[], char str2[]) {
return strcmp(str1, str2);
}int main() {
char string1[100], string2[100];// Taking input for the first string
printf(“Enter the first string: “);
scanf(“%s”, string1);// Taking input for the second string
printf(“Enter the second string: “);
scanf(“%s”, string2);// Calling the function to compare the strings and printing the result
int result = compareStrings(string1, string2);
if (result == 0) {
printf(“The strings “%s” and “%s” are equal.n”, string1, string2);
} else {
printf(“The strings “%s” and “%s” are not equal.n”, string1, string2);
}return 0;
}