fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. char * deblank(const char str[]){
  6. char *buffer = malloc(strlen(str)+1);
  7. if(!buffer){
  8. return NULL;
  9. }
  10.  
  11. char *new = buffer;
  12. while (*str){
  13. if(*str != ' '){
  14. *new++ = *str;
  15. }
  16. ++str;
  17. }
  18. *new = 0;
  19. return buffer;
  20. }
  21.  
  22. int main(void){
  23. char str[] = "This has spaces in it.";
  24. char *new;
  25. new = deblank(str);
  26. puts(new);
  27. free(new);
  28. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Thishasspacesinit.