That's simple enough to fix. we should just ignore spaces. Leading/Trailing/ or just a blank line. (stray tabs or /r as well)
Change the "nukenewline" function to.
static void nukenewline_space(char buf[]) {
unsigned src, dst;
for (src = 0, dst = 0; buf[src] != '\0'; src++) {
if (buf[src] == '\n')
break;
if (isspace((unsigned char)buf[src]))
continue;
buf[dst++] = buf[src];
}
buf[dst] = '\0';
}
Need to add ctype.h as an include too.