void remove_spaces(char* lpsz)
{
auto sptr = lpsz;
auto dptr = lpsz;
while (*dptr = *sptr) { // copy up to and including terminating NUL
    if (*dptr != ' ') dptr++; // but spaces take no slots in the destination
    sptr++;
}
}

#include <stdio.h>
int main(void)
{
    char test[] = { "   Here is  a test   string with  varying     number    of spaces mixed in .  " };
    printf("Before: \'%s\'\n", test);
    remove_spaces(test);
    printf("After : \'%s\'\n", test);
}