Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ctype.h>
- void trim(char *str)
- {
- char *last = NULL, /* last non-space character */
- *next, /* next character to write to */
- *itr;
- for (next = str, itr = str; *itr != '\0'; ++itr)
- {
- *next = *itr;
- if (!isspace((unsigned char) (*itr)))
- last = next;
- if (last != NULL)
- ++next;
- }
- if (last == NULL)
- *next = '\0';
- else
- *(last + 1) = '\0';
- }
Add Comment
Please, Sign In to add comment