aboutsummaryrefslogtreecommitdiff
path: root/read.c
diff options
context:
space:
mode:
Diffstat (limited to 'read.c')
-rw-r--r--read.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/read.c b/read.c
index 879b03e..d64d1b5 100644
--- a/read.c
+++ b/read.c
@@ -15,15 +15,13 @@ void consumespaces(FILE* file) {
ungetc(c, file);
}
-void wsclean(char* txt, size_t sz){ // "string \n \n" -> "string\n\n"
- int nl = 0; // count of newlines
+void wsclean(char* txt, size_t sz){ // "string \n \n" -> "string"
size_t i;
- for (i = sz-1; i >= 0; i--) { // start at end [i-1] and dec
- if (txt[i] == '\n') nl++; // count up newlines
- else if (txt[i] != ' ') break; // and break on unpadded text
+ for (i = sz; i > 0; i--) { // start at end [i-1] and dec
+ // break on non-nl, non-space char
+ if (txt[i-1] != ' ' && txt[i-1] != '\n') break;
}
- memset(txt+i, '\n', nl); // add #nl newlines at [i, i+nl)
- txt[i+nl] = 0; // finish string
+ txt[i] = 0; // finish string
}
char* empty(void) {