Code for Program to compare one string s2 to another string s1. Print the difference of first unmatched characters using strcmp function from string.h in C Programming
#include<stdio.h>
#include<conio.h>
void main()
{
char a[21],b[21];
int i;
clrscr();
printf("\n Please Give The STRING OF A : ");
gets(a);
flushall();
printf("\n Please Give The STRING TO B : ");
gets(b);
i = strcmp(a, b);
if(i < 0)
printf("\nFIRST MISMATCHED CHARACTER IS %d NUMBER LESS",i*-1);
elseif (i > 0)
printf("\nFIRST MISMATCHED CHARACTER IS %d NUMBER HIGHER",i);
else
printf("both are same than \n");
getch();
}
--------------------------------- OUTPUT ---------------------------------
Please Give The STRING OF A : MCA001
Please Give The STRING TO B : MCa001
FIRST MISMATCHED CHARACTER IS 32 NUMBER LESS
--------------------------------------------------------------------------