fork download
  1.  
  2. #include <iostream>
  3. #include <cstring>
  4.  
  5. int main()
  6. {
  7. char str[] = "Hello, my name is John";
  8. size_t len = strlen(str);
  9. size_t change_position = 0;
  10.  
  11. // find the first space character
  12. for (change_position = 0; change_position < len; ++change_position)
  13. if (str[change_position] == ' ')
  14. break; // found it
  15.  
  16.  
  17. if (change_position != len) // if we found a space character
  18. {
  19. for (size_t check_position = change_position; check_position < len; ++check_position)
  20. if (str[check_position] != ' ')
  21. {
  22. str[change_position] = str[check_position];
  23. ++change_position;
  24. }
  25. }
  26. str[change_position] = '\0';
  27. std::cout << str;
  28. }
  29.  
  30.  
Success #stdin #stdout 0s 4244KB
stdin
Standard input is empty
stdout
Hello,mynameisJohn