round: ignore empty lines
authorJann Horn <jann@thejh.net>
Wed, 30 Apr 2014 14:09:43 +0000 (16:09 +0200)
committerJann Horn <jann@thejh.net>
Wed, 30 Apr 2014 14:09:43 +0000 (16:09 +0200)
math/round.c

index e422fd0..f87d3c1 100644 (file)
@@ -6,6 +6,8 @@ int main(int argc, char **argv) {
   double target = strtod(argv[1], NULL);
   char line[128];
   while (fgets(line, sizeof(line), stdin)) {
   double target = strtod(argv[1], NULL);
   char line[128];
   while (fgets(line, sizeof(line), stdin)) {
+    trim_end(line, "\r\n \t");
+    if (!*line) continue;
     double n = strtod(line, NULL);
     double quot = n / target;
     quot = round(quot);
     double n = strtod(line, NULL);
     double quot = n / target;
     quot = round(quot);