All of these are very complicated. You should stick to the utilities at hand. I would highly recommend switching to a std::string
interface and using the standard library algorithms.
Here's how I would solve your issue:
void ignore_switched_letters(const std::string &word){
static std::string computer = "computer";
if(!std::is_permutation(std::begin(computer), std::end(computer), std::begin(word)))
throw std::runtime_error("string is not a permutation of 'computer'");
// do whatever you like with 'word'
}
Of course you don't have to throw exceptions; but where performance isn't a concern, I like to.
A more generic solution may be even better:
template<typename Functor>
void ignore_switched_letters(const std::string &check, const std::string &word, Functor &&f){
if(!std::is_permutation(std::begin(check), std::end(check), std::begin(word)))
throw std::runtime_error(word + " is not a permutation of " check);
f();
}
Then you can have multiple cases to check, like so:
int main(){
std::string computer = "computer";
std::string chair = "chair";
std::string microwave = "microwave";
try{
ignore_switched_letters(computer, "puterc", [](){
std::cout << "is a computer\n";
});
// throws 'std::runtime_error'
ignore_switched_letters(chair, "hair", [](){
std::cout << "is a chair\n";
});
ignore_switched_letters(microwave, "wavemicro", [](){
std::cout << "is a microwave\n";
});
}
catch(const std::exception &e){
std::cerr << e.what() << '\n';
exit(EXIT_FAILURE);
}
}
Which is a nice little convenience.
EDIT
I jumped the gun and missed that you only wanted permutations of 2 characters, I'll leave my answer for interest though.