Guest User

Untitled

a guest
Apr 21st, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. #include <ctype.h>
  2.  
  3. void trim(char *str)
  4. {
  5. char *last = NULL, /* last non-space character */
  6. *next, /* next character to write to */
  7. *itr;
  8.  
  9. for (next = str, itr = str; *itr != '\0'; ++itr)
  10. {
  11. *next = *itr;
  12. if (!isspace((unsigned char) (*itr)))
  13. last = next;
  14. if (last != NULL)
  15. ++next;
  16. }
  17.  
  18. if (last == NULL)
  19. *next = '\0';
  20. else
  21. *(last + 1) = '\0';
  22. }
Add Comment
Please, Sign In to add comment