If statement conditions
Can I use a FOR loop as part of the condition for an IF statement?
For example, my problem is to create a program that will read in a string and compare it to a dictionary file in order to find anagrams of the original word. So I've attacked this by comparing the words of the same length, and anywhere that a letter is the same I'm aiming to change that to a character that isn't a letter, so I can use an IF statement in order to see if the temporary string is made up entirely of these characters, in which case it would be an anagram of the word.
However, because I don't initially know how long the word will be, I've said something like word[i] was the character of the string (where i starts at 0 and increases by 1 everytime), and so wanted to do a for loop until it ran out. Is this allowed by C?
it is hard for me to follow your explanations
could you post the code that shows what are you trying to do but failed?
Its a little messy, but thats what I'm trying to do.
}, printf("%s is an anagram of %s\n" dict[i].name, word);
you can use combination of if, for and flag
int match = 1;
for(k=0;k<strlen(word) && match;k++)
match = 0;
printf("%s is an anagram of %s\n" dict[i].name, word);
Could you run me through in words what this is doing? I don't quite follow it in code.
you set some flag at the begginign of your check
then you walk through your string and check characters with your dictionary word
if characters don't match - you set flag to false and exit the loop
after the loop is ended you check the value of the flag