/ Published in: C++
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
void trim(char *s, const int len) { int end = len - 1; int start = 0; int i = 0; while ((start < len) && (s[start] <= ' ')) { start++; } while ((start < end) && (s[end] <= ' ')) { end--; } if (start > end) { memset(s, '\0', len); return; } for (i = 0; (i + start) <= end; i++) { s[i] = s[start + i]; } memset((s + i), '\0', len - i); }
URL: http://blog.srikanths.net/2008/10/trim-for-c.html