Sunday, 2 November 2014

comparing two string

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char *ptr;
char *ptr1;
int i=0,j=0,k=1;
char str1[20],str2[20];
cout<<"Enter a string:";
gets(str1);
cout<<"Enter another string:";
gets(str2);
ptr1=str2;
cout<<endl<<"Original string is:";
puts(str1);
ptr=str1;
for(i=0,j=0;*(ptr+i)!='\0';i++,j++)
{
      if( *(ptr1+j)==*(ptr+i) )
      k=1;
}
if(k==1)
cout<<endl<<"Similar string";
else
cout<<endl<<"Different string";
getch();
}

No comments:

Post a Comment