From aa2877397feb66d6e644658ab8bee891205113bd Mon Sep 17 00:00:00 2001 From: VIliam Date: Sun, 25 Feb 2024 21:20:22 +0100 Subject: [PATCH] capslock --- cv1/program.c | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/cv1/program.c b/cv1/program.c index 4839991..89c0ecd 100644 --- a/cv1/program.c +++ b/cv1/program.c @@ -1,38 +1,25 @@ #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; - } -} +#include int main() { - char c; int line_count = 0; + char input_char; - while (1) { - int input = getchar(); - - if (input == EOF) { - return -1; - } - - c = (char)input; - c = simulate_caps_lock(c); - - putchar(c); - - if (c == '\n') { + while ((input_char = getchar()) != EOF) { + if (input_char == '\n') { line_count++; } + + if (islower(input_char)) { + input_char = toupper(input_char); + } else if (isupper(input_char)) { + input_char = tolower(input_char); + } + + putchar(input_char); } - printf("%d\n", "Lines count: "line_count); + printf("\nLinesā£count:%d\n", line_count); return 0; } -