diff options
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..328a9cc --- /dev/null +++ b/src/util.c @@ -0,0 +1,38 @@ +/* + * ===================================================================================== + * + * Filename: util.c + * + * Description: + * + * Version: 1.0 + * Created: 01/28/2022 03:47:07 PM + * Revision: none + * Compiler: gcc + * + * Author: YOUR NAME (), + * Organization: + * + * ===================================================================================== + */ +#include <stdlib.h> +#include <ctype.h> +#include <string.h> + +char* trimwhitespace(char* str) { + char* end; + + // Trim leading spaces + while(isspace((unsigned char) *str)) str++; + + if (*str == 0) // All spaces? + return str; + + // trailing spaces + end = str + strlen(str) -1; + while (end > str && isspace((unsigned char)* end)) end--; + + end[1] = '\0'; + + return str; +} |