Files
lab1_git/wcl.c
2025-10-11 13:00:38 +03:00

31 lines
693 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) {
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;
}