From cca3e0833bf80a07feff3a2b3f60f627784dd7a3 Mon Sep 17 00:00:00 2001 From: Miloslav Macko Date: Thu, 22 Feb 2024 14:31:54 +0100 Subject: [PATCH] 22.2 --- cv1/program.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/cv1/program.c b/cv1/program.c index 466e1f0..41d48b1 100644 --- a/cv1/program.c +++ b/cv1/program.c @@ -1,26 +1,32 @@ #include -#include int main() { - int lines_count = 0; int c; + int lines_count = 0; while ((c = getchar()) != EOF) { - if (islower(c)) { - putchar(toupper(c)); - } else if (isupper(c)) { - putchar(tolower(c)); - } else { - putchar(c); - if (c == '\n') { - lines_count++; - } + // Check if the character is a lowercase letter + if (c >= 'a' && c <= 'z') { + // Convert lowercase to uppercase + c = c - 'a' + 'A'; } + // Check if the character is an uppercase letter + else if (c >= 'A' && c <= 'Z') { + // Convert uppercase to lowercase + c = c - 'A' + 'a'; + } + // Check if the character is an end of line + else if (c == '\n') { + // Increment line count + lines_count++; + } + + // Output the character + putchar(c); } - printf("Počet načítaných riadkov: %d\n", lines_count); + // Print the number of lines read + printf("Lines count: %d\n", lines_count); return 0; - - -} \ No newline at end of file +}