From defc7571e7b261a2e8bc63f45b9472ccb81379b7 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 11 Sep 2018 21:11:43 -0700 Subject: add support for line breaks within paragraphs --- journal.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/journal.c b/journal.c index 7507444..4a07261 100644 --- a/journal.c +++ b/journal.c @@ -41,11 +41,18 @@ static void print_entry(char *entry) { strftime(date, sizeof(date), "%Y/%m/%d", localtime(&time)); printf("

%s ", date); - for (int p = getc(f), c = getc(f); p != EOF; p = c, c = getc(f)) { - if (p != '\n') - putchar(p); - else if (c != '\n' && c != EOF) - printf("

"); + for (int c = getc(f), nl = 0; c != EOF; c = getc(f)) { + if (c == '\n') { + ++nl; + continue; + } + + if (nl > 0) { + printf(nl == 1 ? "
" : "

"); + nl = 0; + } + + putchar(c); } fclose(f); -- cgit v1.2.3-70-g09d2