Q:

How to count blank lines from file in C?

So what I'm trying to do is to count blank lines, which means not only just containing '\n'but space and tab symbols as well. Any help is appreciated! :)
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);

A:

Before getting into the line loop increment the emptyLine counter and if an non whitespace character is encountred decrement the emptyLine counter then break the loop.
#include <stdio.h>
#include <string.h>

int getEmptyLines(const char *fileName)
{
    char line[300];
    int emptyLine = 0;
    FILE *fp = fopen("text.txt", "r");
    if (fp == NULL) {
        printf("Error: Could not open specified file!\n");
        return -1;
    }
    else {
        while(fgets(line, 300, fp)) {
            int i = 0;
            int len = strlen(line);
            emptyLine++;
            for (i = 0; i < len; i++) {
                if (line[i] != '\n' && line[i] != '\t' && line[i] != ' ') {
                    emptyLine--;
                    break;
                }
            }
        }
        return emptyLine;
    }
}

int main(void)
{
    const char fileName[] = "text.txt";
    int emptyLines = getEmptyLines(fileName);
    if (emptyLines >= 0) {
        printf("The number of empty lines is %d", emptyLines);
    }
    return 0;
}

