diff options
-rw-r--r-- | include/util.h | 6 | ||||
-rw-r--r-- | src/util.c | 17 |
2 files changed, 23 insertions, 0 deletions
diff --git a/include/util.h b/include/util.h new file mode 100644 index 0000000..e0f92f5 --- /dev/null +++ b/include/util.h @@ -0,0 +1,6 @@ +#ifndef __UTIL_H +#define __UTIL_H + +char *trim(char *s); + +#endif diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..6a061a9 --- /dev/null +++ b/src/util.c @@ -0,0 +1,17 @@ +#include <ctype.h> +#include <string.h> +#include <util.h> + +char * +trim(char *s) +{ + int i; + + while (isspace(*s)) + s++; // skip left side white spaces + for (i = strlen(s) - 1; (isspace(s[i])); i--) + ; // skip right side white spaces + s[i + 1] = '\0'; + + return s; +} |