Last active
September 11, 2018 04:35
-
-
Save AlecTaylor/a7d4c3a9ab79d4e4fcebc9bcf4f49b7b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
static inline void trim(char *&); | |
int main(int argc, char *argv[]) { | |
char *s = " foo bar "; | |
trim(s); | |
printf("s = \"%s\"\n", s); | |
} | |
static inline void *trim(char *&s) { | |
char *end; | |
while (isspace((unsigned char) *s) || ispunct((unsigned char) *s)) s++; | |
if (*s == 0) | |
return s; | |
end = s + strlen(s) - 1; | |
while (end > s && isspace((unsigned char) *end) && ispunct((unsigned char) *s)) end--; | |
end[1] = '\0'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment