Hi. I am needing to write a program that takes a filename, input by the user, and scans and displays the number of words in that file. The delimiters used are space, comma and full stop. The program can't use the standard functions in string.h either

Here's my code, that won't process the file, only displaying a 0 for the number of words, even though it shouldn't.

Any help will be greatly appreciated, and any general pointers on optimisation etc too...

#include <stdio.h>

void main()
{
char letter; /* Variable to hold the current letter for Analysis */
char filename[80]; /* Array to hold the String file name */
int count = 0; /* Count variable to count the number of words */
int begmark; /* Variable to indicate beginning of word */
int endmark; /* Variable to signify the end of a word */
FILE *pfile; /* File Pointer */

printf("Please enter the file name :\n\n");
gets(filename);
printf("\n");
/* ADD CODE FOR FILENAME ERROR HANDLING HERE WILL DO LATA */

while(!feof)
{
letter = fgetc(pfile);

switch(letter)
{
case ' ': case '.': case '\n': case ',':
endmark = 1;
if(endmark == 1 && begmark == 1)
{
count = count + 1;
begmark = 0;
endmark = 0;
}
break;
default:
begmark = 1;
}
}
printf("The total number of words in the file is %d\n", count);
}