From a277448c46da9dff697fdcdacae2e554081fdec6 Mon Sep 17 00:00:00 2001 From: VIliam Date: Sat, 24 Feb 2024 20:23:56 +0100 Subject: [PATCH] capslock --- cv1/program.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/cv1/program.c b/cv1/program.c index e9ce4d2..c40169d 100644 --- a/cv1/program.c +++ b/cv1/program.c @@ -1,39 +1,37 @@ #include +char simulate_caps_lock(char c) { + if ('a' <= c && c <= 'z') { + return c - ('a' - 'A'); + } else if ('A' <= c && c <= 'Z') { + return c + ('a' - 'A'); + } else { + return c; + } +} + int main() { - char input_char; + char c; int line_count = 0; while (1) { - int read_result = scanf("%c", &input_char); + int input = getchar(); - if (read_result == EOF) { - break; + if (input == EOF) { + break; // Koniec súboru (EOF) } - - if (input_char >= 'a' && input_char <= 'z') { - input_char = input_char - 'a' + 'A'; - } - - else if (input_char >= 'A' && input_char <= 'Z') { - input_char = input_char - 'A' + 'a'; - } - - else if (input_char == '\n' || (input_char >= 32 && input_char <= 126)) { - if (input_char == '\n') { - line_count++; - } - } else { - - continue; - } + c = (char)input; + c = simulate_caps_lock(c); - - printf("%c", input_char); + putchar(c); + + if (c == '\n') { + line_count++; + } } - printf("%d\n", line_count); + printf("\nPocet nacitanych riadkov: %d\n", line_count); return 0; }