Pages

Visitors

Thursday 5 January 2012

string compare without strcmp()


#include <stdio.h>
#include <conio.h>
#include <string.h>

main()

{
    char s1[30],s2[20];

   int i,length = 0,temp;

   printf("enter string 1: ");
   gets(s1);

   printf("\n enter string 2: ");

   gets(s2);

   for(i=0;s1[i]!='\0';i++)

   {
       if(s1[i]== s2[i])

       temp = 1; else temp = 0;
   }

   if (temp == 1)

   printf("both the strings are same");

   else
   printf("both strings are not same.");
    getch();
}

No comments:

Post a Comment