stringToChar() is giving the error, we need to see the code for that.
string letter = s.substr(n, 1);
the above line does give you a string with length 1, so looking at the error message one has to presume that the character you picked out is a space!
or there is a bug in stringToChar().
@tipaye
How did you determine what stringToChar() parameters are? It's name alone implies it takes a string and returns a char.
Also, OP makes the point that this is a runtime error not compile time.