Skip to content

Instantly share code, notes, and snippets.

@nramsbottom
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save nramsbottom/0b3dcea5b6ea39ad890c to your computer and use it in GitHub Desktop.

Select an option

Save nramsbottom/0b3dcea5b6ea39ad890c to your computer and use it in GitHub Desktop.
char *trim(char *s) {
size_t length = strlen(s);
while (length > 0) {
if (s[0] == ' ')
memmove(s, s + 1, --length);
else if (s[length - 1] == ' ')
s[--length] = '\0';
else
--length;
}
return s;
}
int iswhitespace(char c) {
if (c == '\t') return 1;
if (c == ' ') return 1;
return 0;
}
char *trim(char *s) {
size_t length = strlen(s);
while (length > 0) {
if (iswhitespace(*s))
memmove(s, s + 1, --length);
else if (iswhitespace(s[length - 1]))
s[--length] = '\0';
else
--length;
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment