fork download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. void trim (char *s)
  5. {
  6. int i;
  7.  
  8. while (isspace (*s)) s++; // skip left side white spaces
  9. for (i = strlen (s) - 1; (isspace (s[i])); i--) ; // skip right side white spaces
  10. s[i + 1] = '\0';
  11. printf ("%s\n", s);
  12. }
  13.  
  14. int main(void) {
  15. char str[] = "Hello World ";
  16. printf("%s!!\n", str);
  17. trim(str);
  18. printf("%s!!\n", str);
  19. }
Runtime error #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
Hello World     !!
Hello World
Hello World!!