Files
lab1_letscontinue/wcl.c
2025-12-04 22:31:28 +03:00

32 lines
576 B
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) {
printf("Использование: %s <путь_к_файлу>\n", argv[0]);
return 1;
}
for (int i = 1; i < argc; i++) {
FILE *file = fopen(argv[i], "r");
if (file == NULL) {
printf("Ошибка: не удалось открыть файл '%s'\n", argv[1]);
continue;
}
int line_count = 0;
int ch;
while ((ch = fgetc(file)) != EOF) {
if (ch == '\n') {
line_count++;
}
}
printf("Строк: %d\t%s\n", line_count, argv[i]);
fclose(file);
}
return 0;
}