C program to compare two strings without using strcmp

C program to compare two strings without using strcmp()
This C program is  to compare a string with another string without using strcmp() function.

Program:

#include<stdio.h>
#include<conio.h>
/* c program to compare two strings without using strcmp() by SlashMyCode.com */
int main() 
{
   char str1[20], str2[20];
   int i;

   printf("Enter 1st string : ");
   gets(str1);
   printf("\nEnter 2nd string : ");
   gets(str2);

   i = 0;
   while (str1[i] == str2[i] && str1[i] != '\0')
      i++; /* incrementing i since we want to check next element in string */
   if (str1[i] > str2[i])
      printf("str1 > str2");
   else if (str1[i] < str2[i])
      printf("str1 < str2");
   else
      printf("str1 = str2");
/* c program to compare two strings without using strcmp() by SlashMyCode.com */
   getch();

}


Output:


 output of C program to compare two strings without using strcmp


Flowchart:
flowchart of C program to compare two strings without using strcmp





No comments:

Post a Comment

Feel free to ask us any question regarding this post