fork download
  1. #include <iostream>
  2. #include <iostream>
  3.  
  4. char* skip_if( char* s, const char* ss )
  5. {
  6. char* p = s;
  7. const char* pp = ss;
  8. while( *p && *pp && *p == *pp )
  9. p++, pp++;
  10. return *pp ? s : p;
  11. }
  12.  
  13. void remove( char* s, const char* ss )
  14. {
  15. char *ps = s; // source
  16. char *pd = s; // destination
  17. while( *ps )
  18. {
  19. ps = skip_if( ps, ss );
  20. *pd++ = *ps++;
  21. }
  22. *pd = 0;
  23. }
  24.  
  25. int main()
  26. {
  27. using namespace std;
  28.  
  29. char str[] = "this that there this that there";
  30. const char* substr = "th";
  31. remove( str, substr );
  32.  
  33. cout << str;
  34.  
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
is at ere is at ere