I am trying to write a code to remove all the leading, trailing and middle of the sentence spaces but to keep only one space between the words.
For example if the input
Use two pointers. The first points at the next character to read, and the second points at the location to write.
If you read two spaces in a row, don't advance the write pointer.
Another approach you may want to consider is to use strtok with " " as a delimiter.
" "