C Program to Compare Two Strings Without Using Library Function [Strcmp]

August 24, 2024 No Comments » Hits : 536





C Program to Compare Two Strings Without Using Library Function

#include<stdio.h>
#include<conio.h>
void main()
{
char str1[30],str2[30];
int i;
printf("\n Enter two strings :");
gets(str1);
gets(str2);
//loop for comparison
 i=0;
 while(str1[i]==str2[i] && str1[i]!='\0')
  i++;
 if(str1[i] > str2[i])
  printf("\nstr1 > str2");
 else
  if(str1[i] < str2[i])
   printf("\nstr1 < str2");
  else
   printf("\nstr1 = str2");
 getch();
}

Incoming search terms: