C program to compare the given strings
kw.c
#include <stdio.h>
#include <string.h>
int main()
{
    char a[20], b[20];
    printf("———————————————————————————————————————————");
    printf("\nProgram to compare two strings");
    printf("\n———————————————————————————————————————————");
    printf("\nEnter the 1st string ");
    scanf("%s", a);
    printf("\nEnter the 2nd string ");
    scanf("%s", b);
    int c = strcmp(a, b);
    if (c == 0)
    {
        printf("\nStrings are equal");
    }
    else
    {
        printf("\nStrings are unequal");
    }
    printf("\n———————————————————————————————————————————\n");
    return 0;
}
Output
kodingwindow@kw:~$ gcc kw.c
kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program to compare two strings ——————————————————————————————————————————— Enter the 1st string HELLO Enter the 2nd string WORLD Strings are unequal ——————————————————————————————————————————— kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program to compare two strings ——————————————————————————————————————————— Enter the 1st string WORLD Enter the 2nd string WORLD Strings are equal ——————————————————————————————————————————— kodingwindow@kw:~$
Advertisement