Hey guys;
This is my code for a project I was working on, the code is supposed to accept two strings from the user and determine if they are anagrams (by removing spaces and non characters/numbers from the strings). The code works correctly ... the first time, but when it loops to have the user enter two new words, it crashes. I cant for the life of me figure out why, any hints/tips would be much appreciated.
The reason the error is triggered on the second pass of the loop, is the trailing newline '\n' remaining in the input buffer after cin >> ask; at line 102. That can be fixed by the use of cin.ignore().
102 103
cin >> ask;
cin.ignore(1000, '\n');
As for the actual error which causes the crash, it looks like your code cannot handle a zero-length string. That's something you should look at fixing either at the stage of getting user input, or in the anagram preprocess() function.