fork(4) download
  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. void TrimRight(char * s)
  7. {
  8. size_t space_counter = 0;
  9.  
  10. for(;;)
  11. {
  12. if (!*s) break;
  13.  
  14. if (*s == ' ')
  15. space_counter++;
  16. else
  17. space_counter = 0;
  18.  
  19. ++s;
  20. }
  21.  
  22. *(s - space_counter) = '\0';
  23. }
  24.  
  25. int main(int argc, char *argv[])
  26. {
  27. char s[8193];
  28. scanf("%8192[ 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]", s);
  29. printf("%s:\n%s\n", "Original string", s);
  30. TrimRight(s);
  31. printf("%s:\n%s\n", "Trimmed string", s);
  32. return 0;
  33. }
Success #stdin #stdout 0s 3460KB
stdin
fskldfds fds fffffffsalkdsajflk lkm lfaskmalm lmk            aslkdmklsm dkm lakms lkm lmlaskm lkm l lakmdl kfnkjfn KN kj nEJfkd nDfn kj nkj n                                                                                                                                                                                                                                                                                                       
stdout
Original string:
fskldfds fds fffffffsalkdsajflk lkm lfaskmalm lmk            aslkdmklsm dkm lakms lkm lmlaskm lkm l lakmdl kfnkjfn KN kj nEJfkd nDfn kj nkj n                                                                                                                                                                                                                                                                                                       
Trimmed string:
fskldfds fds fffffffsalkdsajflk lkm lfaskmalm lmk            aslkdmklsm dkm lakms lkm lmlaskm lkm l lakmdl kfnkjfn KN kj nEJfkd nDfn kj nkj n