generarxml/string.c

28 lines
499 B
C
Raw Normal View History

2016-10-16 14:16:03 -03:00
#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;
}