fork(5) download
  1. #include <iostream>
  2. #include <algorithm> // for copy_if()
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. void remove_extra_whitespaces(const char *input, char *output)
  7. {
  8. //output.clear(); // unless you want to add at the end of existing sring...
  9. unique_copy (input, input+strlen(input)+1, output, [](char a,char b){ return isspace(a) && isspace(b);});
  10. cout << output<<endl;
  11. }
  12.  
  13. int main(int argc, char **argv)
  14. {
  15. cout << "testing 2 ..\n";
  16.  
  17. char input[0x255] = "asfa sas f f dgdgd dg ggg";
  18. char output[0x255] = "NO_OUTPUT_YET";
  19. remove_extra_whitespaces(input,output);
  20.  
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
testing 2 ..
asfa sas f f dgdgd dg ggg