Course Content
Detailed Content of Programming in C
0/1
Introduction
0/1
Structure of C program
0/1
Answers of ‘C’ Pointers Programs
0/1
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;
}