aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--center.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/center.c b/center.c
index 37a643e..be6d9ee 100644
--- a/center.c
+++ b/center.c
@@ -113,8 +113,10 @@ center(FILE *fp)
tabs++;
}
- len = lenfunc(line) + tabs * 8 - tabs + 1;
- printf("%*s", ((int) width - len) / 2 + len, line);
+ len = lenfunc(line) + tabs * 8 - tabs;
+ for (int i = (width - len) / 2; i; i--)
+ putchar(' ');
+ fputs(line, stdout);
}
if (ferror(fp)) {
warn("getline");
@@ -145,6 +147,9 @@ utf8len(const char *s)
while (*s)
l += (*s++ & 0xC0) != 0x80;
+ if (l > 0 && s[-1] == '\n')
+ l--;
+
return l;
}