"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Saturday, February 20, 2010

Write a function that checks whether or not two arrays (of characters ) are identical, that is, whether they have same characters and all characters in corrosponding positions are equal.


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


void main()
{
char sen1[50], sen2[50];
void chk_eq(char str1[], char str2[]);
cout<< "\n Enter String1 :";
gets(sen1);


cout<<"\n Enter String 2:";
gets(sen2);


chk_eq(sen1, sen2);


}


void chk_eq(char str1[], char str2[])
{
int l1,l2;


l1 = strlen(str1);
l2 = strlen(str2);


if(l1 == l2)
{
cout<<" \ n Two String are NOT equal ";
getch();
exit(1);
}


for( int i = 0; i<= l1 - 1 ; i++)
{
  if(str1[i] ! = str2[i])
   {


     cout<<" \ n Two String are NOT equal ";
     getch();
     exit(1);
   }
}


cout<< "\n Two Strings are EQUAL lengthwise , characterwise and casewise ";
getch();
}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.