0

help me to create a program determine if the input word is anagram or not anagram of if the words are the same they are identical.......here's my code can you fix it...................plss...

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

int main(){
int menu,i,j,ctr=0;
char fw[20],sw[20],let;
do
{clrscr();
printf ("[1] Enter String\n");
printf ("[2] Exit\n");
printf ("Please choose from the menu:");
scanf ("%d",&menu);
if (menu==1){
printf ("Enter the first word:");
scanf ("%s",&fw);
printf ("Enter the second word:");
scanf ("%s",&sw);
}
for (i=0;i<strlen(fw);i++)
{
let=fw[i];
for (j=0;j<strlen(sw);i++)
{
if (let==sw[j]);{
ctr++;
break;}
}
}
getch();
ctr=0;
}
while (menu!=2);
printf ("Press any key to terminate");
getch();
return 0;

}

Edited by Nick Evan: Split thread, added tags

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by TotoTitus
0

There are a few problems in your code :

for (j=0;j<strlen(sw);i++)
//should be
for (j=0;j<strlen(sw);j++)

And the ctr variable isn't used at all - it's just being incremented and set back to 0.
Other than that, you should revise anagram logic - each word but be a permutation of the same symbols.
Like:
BLARGH
GLARHB
So, just for starters, the two strings should have the same length.

Edited by TotoTitus: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.