From 5c799b0389b2af9dd12a4d9ccbea121822f88888 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Thu, 18 Apr 2024 03:07:42 +0400 Subject: [PATCH] 1.8 --- The C Programming Language/1.8.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 The C Programming Language/1.8.c diff --git a/The C Programming Language/1.8.c b/The C Programming Language/1.8.c new file mode 100644 index 0000000..979ff18 --- /dev/null +++ b/The C Programming Language/1.8.c @@ -0,0 +1,23 @@ +#include + +main() +{ + int c; + int count_tabs = 0; + int count_newlines = 0; + int count_spaces = 0; + + while ((c = getchar()) != EOF) + { + if (c == '\t') + ++count_tabs; + if (c == '\n') { + ++count_newlines; + printf("\n\ntabs: %d, spaces: %d, newlines: %d\n", count_tabs, count_spaces, count_newlines); + } + if (c == ' ') + ++count_spaces; + } + + printf("\n\ntabs: %d, spaces: %d, newlines: %d\n", count_tabs, count_spaces, count_newlines); +}