Sunday, March 21, 2010

A C++ PROGRAM TO COMPARE TWO STRINGS WITHOUT USING strcmp() FUNCTION

main()
{
 clrscr();
 char a[25],b[25];
 int cnt=1,i=1;
 cout<<"\n ENTER THE STRING 1 : ";
 cin>>a;
 cout<<"\n ENTER THE STRING 2 : ";
 cin>>b;

 while(a[i]!='\0' && b[i]!='\0')
 {
  if(a[i]==b[i])
  {
   cnt++;
  }
  else
  {
   cout<<"\n\n THE TWO STRINGS ARE NOT EQUAL";
  }
  i++;
 }

 if(i==cnt)
 {
  int n;
  clrscr();
  cout<<"\n\n\t\t~~~~~~~~~~COMPARISON RESULT~~~~~~~~~~~";
  cout<<"\n\n THE GIVEN TWO STRINGS ARE ONE & SAME ";
 }

 getch();
 return 0;
}

3 comments: