I have an anagram program that if you type in a word's characters in any order, the dictionary file will be able to export it. However, my assignment is to build words that are shorter than the inputted search area in a one-to-one letter correspondance. An example of this would be inputting "abel's" and returning "abe, abe's, abel, abel's, able, ables", or whatever the words could fit the criteria.
I've had suggestion from my classmate that I should convert the string to a char, but I'm unsure if this is what I should perform (my test of this is commented out).
Do your anagram words need to have meaning in dictionary?
Anyway, yes you need to work with the string as a char. You could do a brute-force way using permutation. For example, a given string is '123'. When you look for permutation of any length, you would get '1', '2', '3', '12', '13', '21', '23', '31', '32', '123', '132', '213', 231', '312', '321'.
I just wrote an annagram program simmilar to yours. My program didn't do the chopped up forms of a word. It only used the exact number of letters entered by the user. I wrote the input words into a struct that contained two items. The first was the word as entered by the user, the second was the alphbetized version. We then compared the sorted word against the sorted dictionary list of words. I think in your case you need to store every possible combination of the users input word and compare. Look up how to use permitations. I am not sure, but there could be a built in function that can do this.
STL has something that can help you: an algorithm that performs permutation. You can apply it to a string, so that you get different words each time, and than comparing to your inner dictionary to see if they form indeed a word. You can save these string in a vector/other form of container.
using namespace std;
You can also chop the string (saw you mentioned that it could be truncated), than search for it in your dictionary.
What would be the best way to utilize a char inside the next_permutation function? I try to run it but get errors C2228 and C2780 when using this
}while(next_permutation(inputArray.begin(),input.Array.end())); //error occurs here
//error C2228: left of '.begin' must have class/struct/union
//error C2228: left of '.end' must have class/struct/union
//error C2780: 'bool std::next_permutation (_BidIt,_BidIt,_Pr)': expects 3 arguments - 2 provided