From 5a74eaae4d6d33857fa365340f616f87d1849d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1=C5=A1?= Date: Wed, 21 Feb 2024 15:45:04 +0000 Subject: [PATCH] Update 'cv1/program.c' --- cv1/program.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cv1/program.c b/cv1/program.c index be76811..afd86b6 100644 --- a/cv1/program.c +++ b/cv1/program.c @@ -3,33 +3,34 @@ int main() { int c = 0; int lines_count = 0; - int last_char_was_newline = 0; - + int was_newline = 0; while ((c = getchar()) != EOF) { - - last_char_was_newline = 0; + + was_newline = 0; - + if (c >= 'a' && c <= 'z') { c = c - 'a' + 'A'; } - + else if (c >= 'A' && c <= 'Z') { c = c - 'A' + 'a'; } if (c == '\n') { lines_count++; - last_char_was_newline = 1; + was_newline = 1; } putchar(c); } - if (!last_char_was_newline) { + if (!was_newline && c != EOF) { putchar('\n'); } + + printf("Lines count: %d\n", lines_count); return 0;