/ Published in: C
These functions will allow you to trim left and right on a string
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
char *trim(char *str) { char *out = str; out = trim_left(out); out = trim_right(out); return out; } char *trim_left(char *str) { if(str[0] != ' ' || str[0] == '\0') return str; return trim_left(str++); } char *trim_right(char *str) { if(len == 0 || str[len] != ' ') return str; return trim_right(str); }