count number of whitespaces in C

abhijangda

Padawan
Hello everybody, I was doing a simple program to count number of whitespaces in a text file but I am stuck at it.
Here is the code

Code:
void main()
{
    FILE *from;
    int ch,count;
    int c;
    from = fopen("newfile","r");
    
    while ((c = fgetc(from)) != EOF)
    { 
        if (c == '\n' || c == '\t' || c == ' ')
        {
            count++;
           
            }
        }
    printf("%d",count);
    fclose(from);
    }

and in the file it is written

HELLO EVERY ONE \n

and it prints count in millions!!
whats the problem here please tell me!!
 
Top Bottom