# count number of whitespaces in C



## abhijangda (May 10, 2011)

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


```
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!!


----------



## pulkitpopli2004 (May 10, 2011)

initialise the count to zero


----------



## abhijangda (May 10, 2011)

ooppsss!!! Didn't remember to that
thx!!!


----------

