Files
lab1_git/wcl.c
Ваше Имя 57fd51943e first commit
2025-10-11 05:57:11 -04:00

33 lines
1.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
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;
}