I didn't run into problems with long string (at least up to 3662 characters - I didn't try more) as long as the longest unbroken string of characters (single word) was less than <your guess here>
. Here's a hint.
while (charText[rightEdge] != SPACE_CHAR) {
--rightEdge;
}
Trace through what happens after you have moved 'rightEdge' with this line rightEdge = leftEdge + SPACES;
and you encounter a long unbroken string of characters.