fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. void TrimRight(char *s)
  6. {
  7. char *lastNonSpace = s - 1;
  8. while (*s != '\0')
  9. {
  10. if (*s != ' ') {
  11. lastNonSpace = s;
  12. }
  13.  
  14. s++;
  15. }
  16.  
  17. *(lastNonSpace + 1) = '\0';
  18. }
  19.  
  20. int main() {
  21. char d[] = " c";
  22. cout << d<< 1<<endl;
  23. TrimRight(d);
  24. cout << d<< 1<<endl;
  25. }
Success #stdin #stdout 0s 4556KB
stdin
Standard input is empty
stdout
          c1
          c1