10 Mar 2013

COMPARE strings

/*

program to compare two strings....

*/

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

void main()
{
 

clrscr();
 

char a[50],b[50];
int i,j,k=0;
 

cout<<"Enter the first string:"<<endl;
gets(a);
cout<<"Enter the second string:"<<endl;
gets(b);
 

if(strlen (a)!=strlen (b))
 cout<<"Strings are not equal."<<endl;
else
 {
  for(i=0,j=0;a[i]!='\0';i++,j++)
 {
  if(a[i]==b[j])
   continue;
  else
   k=1;
   break;
 }
if(k>0)
 cout<<"Strings are not equal."<<endl;
else
 cout<<"Strings are equal."<<endl;
}


getch();
}


Categories: , ,

0 comments:

Post a Comment

Copyright © UPgradeCODING | Powered by Blogger