commit 57fd51943e1b3f34b94ac9deeb9556a4b87312d2 Author: Ваше Имя Date: Sat Oct 11 05:57:11 2025 -0400 first commit diff --git a/wcl b/wcl new file mode 100755 index 0000000..d85e892 Binary files /dev/null and b/wcl differ diff --git a/wcl.c b/wcl.c new file mode 100644 index 0000000..349f936 --- /dev/null +++ b/wcl.c @@ -0,0 +1,32 @@ +#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; // Переходим к следующему файлу + } + + int lines = 0; + int ch; + // Считаем количество символов новой строки + while ((ch = fgetc(file)) != EOF) { + if (ch == '\n') { + lines++; + } + } + + fclose(file); + printf("%d\t%s\n", lines, argv[i]); // Выводим результат + } + + return 0; +}