See I have 2 string, i need to check whether 2nd sting is jumbled form of first sting
Output is coming equal; how come?
If string 1 is "dabcd" and string 2 is "bcadd" then it should show similar strings.
Any one can suggest any other easy way to do this....
Code:
#include<stdio.h>
int main()
{
char a[]="abcd";
char b[]="zdab";
char temp = '0';
int i=0,j=0;
int n=sizeof(a);
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
temp =a[j];
a[j] = a[j+1];
a[j+1]=temp;
}
if(b[j]>b[j+1])
{
temp =b[j];
b[j] = b[j+1];
b[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
{
printf("%c %c\n",a[i],b[i]);
}
if(strcmp(a,b)==0)
printf("similar and jumbled");
else
printf("unequal");
return 0;
}
output :
a a
b b
c d
d z
similar and jumbled