Q:

C program to compare two strings without using strcmp() function

0

C program to compare two strings without using strcmp() function

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
 
int compare_strings(char [], char []); 
 
int main()
{
   char a[1000], b[1000];
 
   printf("Input a string\n");
   gets(a);
 
   printf("Input a string\n");
   gets(b);
 
   if (compare_strings(a, b) == 0)
      printf("Equal strings.\n");
   else
      printf("Unequal strings.\n");
 
   return 0;
}
 
int compare_strings(char a[], char b[])
{
   int c = 0;
 
   while (a[c] == b[c]) {
      if (a[c] == '\0' || b[c] == '\0')
         break;
      c++;
   }
 
   if (a[c] == '\0' && b[c] == '\0')
      return 0;
   else
      return -1;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now