кто-то может показать мне, как получить общее количество строк в текстовом файле на языке программирования C?
Это один подход:
FILE* myfile = fopen("test.txt", "r");
int ch, number_of_lines = 0;
do
{
ch = fgetc(myfile);
if(ch == '\n')
number_of_lines++;
} while (ch != EOF);
// last line doesn't end with a new line!
// but there has to be a line at least before the last line
if(ch != '\n' && number_of_lines != 0)
number_of_lines++;
fclose(myfile);
printf("number of lines in test.txt = %d", number_of_lines);