Update 'cv1/program.c'

This commit is contained in:
Tamáš 2024-02-21 15:40:44 +00:00
parent 81e1f67758
commit d9cc1c347d

View File

@ -1,11 +1,15 @@
#include <stdio.h> #include <stdio.h>
int main() { int main() {
int c = 0; int c = 0;
int lines_count = 0; int lines_count = 0;
int last_char_was_newline = 0;
while ((c = getchar()) != EOF) { while ((c = getchar()) != EOF) {
last_char_was_newline = 0;
if (c >= 'a' && c <= 'z') { if (c >= 'a' && c <= 'z') {
c = c - 'a' + 'A'; c = c - 'a' + 'A';
} }
@ -13,19 +17,20 @@ int main() {
else if (c >= 'A' && c <= 'Z') { else if (c >= 'A' && c <= 'Z') {
c = c - 'A' + 'a'; c = c - 'A' + 'a';
} }
if (c == '\n') { if (c == '\n') {
lines_count++; lines_count++;
last_char_was_newline = 1;
} }
putchar(c); putchar(c);
} }
if (lines_count > 0) { if (!last_char_was_newline) {
putchar('\n'); putchar('\n');
} }
printf("Lines count: %d\n", lines_count); printf("Lines count: %d\n", lines_count);
return 0; return 0;
} }