In theory if string is "   " by example, to the end of the while, ptr_end always will be < str.

Example:
string: "   "\0
string with "positions": 2"345"\0
str initial position = 3

ptr_end initial position = 5
to the end of while ptr_end position = 2 because always that ptr_end >= str and actual char is space, ptr_end--

that's why ptr_end < str


Sorry if is confused, but is something difficult for me explain certains things in english.

PD: I changed == ' ' by isspace again.