From d963f0cb6eb594d7760189b921d6a2adfb7d8eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=88=D0=B5=20=D0=98=D0=BC=D1=8F?= Date: Sat, 18 Oct 2025 05:35:35 -0400 Subject: [PATCH] add new file --- wcl.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/wcl.c b/wcl.c index 349f936..a114e4f 100644 --- a/wcl.c +++ b/wcl.c @@ -1,31 +1,46 @@ #include +#include int main(int argc, char *argv[]) { - // Проверяем, переданы ли аргументы командной строки if (argc < 2) { fprintf(stderr, "Использование: %s <файл1> [файл2 ...]\n", argv[0]); return 1; } - // Обрабатываем каждый переданный файл for (int i = 1; i < argc; i++) { FILE *file = fopen(argv[i], "r"); if (file == NULL) { fprintf(stderr, "Ошибка: не удалось открыть файл '%s'\n", argv[i]); - continue; // Переходим к следующему файлу + continue; } int lines = 0; + int words = 0; + int bytes = 0; int ch; - // Считаем количество символов новой строки + int in_word = 0; + while ((ch = fgetc(file)) != EOF) { + bytes++; if (ch == '\n') { lines++; } + if (isspace(ch)) { + if (in_word) { + words++; + in_word = 0; + } + } else { + in_word = 1; + } + } + + if (in_word) { + words++; } fclose(file); - printf("%d\t%s\n", lines, argv[i]); // Выводим результат + printf("%d\t%d\t%d\t%s\n", lines, words, bytes, argv[i]); } return 0;