그래서 내가하려고하는 것은 공백 행을 계산하는 것입니다. 이는 공백뿐만 아니라 '\ n'그러나 스페이스와 탭 기호도 포함한다는 것을 의미합니다. 어떤 도움을 주셔서 감사합니다! :)C에서 파일의 빈 줄을 계산하는 방법은 무엇입니까?
char line[300];
int emptyline = 0;
FILE *fp;
fp = fopen("test.txt", "r");
if(fp == NULL)
{
perror("Error while opening the file. \n");
system("pause");
}
else
{
while (fgets(line, sizeof line, fp))
{
int i = 0;
if (line[i] != '\n' && line[i] != '\t' && line[i] != ' ')
{
i++;
}
emptyline++;
}
printf("\n The number of empty lines is: %d\n", emptyline);
}
fclose(fp);
매뉴얼 페이지를 읽지 않는 이유 - http://www.cplusplus.com/reference/cstdio/fgets/ -'fgets'는 한 줄을 읽습니다. 비어 있는지 확인해야합니다. –
else 블록을 사용하여'emptyline ++'을'continue' 또는'wrapped해야합니다 – Billie