This is still error-prone -- `i` could be the last valid index, upon which this code would increment it and try to make an invalid reference. It's probably best not to use `c` in the `else` clause, and just use something like
`while ((i < length_of_s) && (static_cast<unsigned char>(str[i]))`. That way, the string accesses are always guarded by the length check.