WAP to compare two strings

Write a program to compare two strings without using string function

#include<stdio.h>

int main() {
   char str1[30], str2[30];
   int i;

   printf("\nEnter two strings :\n");
   gets(str1);
   gets(str2);

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

   return (0);
}

Output

Enter two strings :
nawaraj
shah
str1 < str2 alphabetically

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments