Wednesday, August 17, 2011

Comparing String without using library functions

//WAP to Compare two strings without using library functions
#include<stdio.h>
int main()
{
   char str1[1000], str2[1000];
   int i, flag=0;

   printf("Enter the First string :\n");
   gets(str1);

   printf("Enter the Second string :\n");
   gets(str2);

   for(i=0;str1[i]!='\0';i++)
   {
  if(str1[i]==str2[i])
      continue;
  else
  {
      flag=1;
      break;
  }
   }
   if(flag==0)
printf("Strings are equal \n");
   else
printf("Strings are not equal \n");
   return 0;
}

/******************OUTPUT***********************
Enter the First string :
abhishek wadhwa
Enter the Second string :
abhishek wadhwa
Strings are equal

*/

No comments:

Post a Comment

Programming the Whole World!