fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void trim(char **s) {
  6. while ((*s)[0] == ' ') (*s)++;
  7. int max = strlen(*s);
  8. while ((*s)[--max] == ' ');
  9. (*s)[max+1] = '\0';
  10. }
  11. int main() {
  12. char *s = (char *)malloc(50+1);
  13. strcpy(s, " asdf fdsa fdsa ");
  14. printf("\"%s\"\n", s);
  15. trim(&s);
  16. printf("\"%s\"\n", s);
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0.01s 2856KB
stdin
Standard input is empty
stdout
"        asdf   fdsa fdsa    "
"asdf   fdsa fdsa"