Posted By

zava on 08/12/10


Tagged

textmate deblank


Versions (?)

deblank


 / Published in: C
 

  1. // Remove multiple space characters in a string.
  2. // Ansi string and UTF-8 only!
  3.  
  4. void deblank(char* string)
  5. {
  6. char* s = string;
  7. char* c = string;
  8. do
  9. {
  10. while (*c == ' ') c++;
  11. *s++ = *c;
  12. if (*c == '\0') break;
  13. if (*++c == ' ')
  14. {
  15. *s++ = ' ';
  16. c++;
  17. }
  18. } while (1);
  19. }
  20.  
  21. int main()
  22. {
  23. char s[] = "abc def ghj klmn.";
  24. deblank(s);
  25. printf("%sn", s);
  26. return 0;
  27. }

Report this snippet  

You need to login to post a comment.