fork download
  1. void remove_spaces(char* lpsz)
  2. {
  3. auto sptr = lpsz;
  4. auto dptr = lpsz;
  5. while (*dptr = *sptr) { // copy up to and including terminating NUL
  6. if (*dptr != ' ') dptr++; // but spaces take no slots in the destination
  7. sptr++;
  8. }
  9. }
  10.  
  11. #include <stdio.h>
  12. int main(void)
  13. {
  14. char test[] = { " Here is a test string with varying number of spaces mixed in . " };
  15. printf("Before: \'%s\'\n", test);
  16. remove_spaces(test);
  17. printf("After : \'%s\'\n", test);
  18. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Before: '   Here is  a test   string with  varying     number    of spaces mixed in .  '
After : 'Hereisateststringwithvaryingnumberofspacesmixedin.'