Skip to content

Instantly share code, notes, and snippets.

@anjerodesu
Created March 6, 2016 03:56
Show Gist options
  • Save anjerodesu/8faf407b51ec78946910 to your computer and use it in GitHub Desktop.
Save anjerodesu/8faf407b51ec78946910 to your computer and use it in GitHub Desktop.
string trmwsp(string s) {
if (strlen(s) < 1) {
return empstr();
}
while (isspace(*s)) s++;
if (*s == 0) {
return empstr();
}
string end = s + strlen(s) - 1;
while (end > s && isspace(*end)) end--;
end++;
string ts = malloc(sizeof(char *) * strlen(s));
size_t len = strlen(s) - strlen(end);
memcpy(ts, s, len);
return ts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment