28 lines
499 B
C
28 lines
499 B
C
#include <string.h>
|
|
#include <ctype.h>
|
|
|
|
char *trim(char *str) {
|
|
char *end;
|
|
|
|
/* Trim leading space */
|
|
while (isspace((unsigned char) *str)) {
|
|
str++;
|
|
}
|
|
|
|
if(*str == 0) {
|
|
/* All spaces? */
|
|
return str;
|
|
}
|
|
|
|
/* Trim trailing space */
|
|
end = str + strlen(str) - 1;
|
|
while (end > str && (isspace((unsigned char) *end) || *end == '\r' || *end == '\n')) {
|
|
end--;
|
|
}
|
|
|
|
/* Write new null terminator */
|
|
*(end + 1) = 0;
|
|
|
|
return str;
|
|
}
|