C program to compare two strings without using library function

C program to compare two strings without using library function:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().



#include<stdio.h>
main()
{
   char str1[30],str2[30];
   int i;
   printf("Enter two strings :");
   gets(str1);
   gets(str2);

   i=0;
   while(str1[i] == str2[i] && str1[i] != '\0')
      i++;
   if(str1[i] > str2[i])
     printf("%s > %s",str1,str2);
   else if(str1[i] < str2[i])
     printf("%s < %s",str1,str2);
   else
     printf("%s = %s",str1,str2);
}

OUTPUT:

 

Leave a Reply

Your email address will not be published. Required fields are marked *

2 × 5 =