program hangs during runtime
At runtime, after I type in the name of my executible, it newlines and hangs. I get no error at compile time. I'll post the file I'm reading from if anyone wants it. Is there a problem with the code?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main () {
char buf[11]; /* file buffer area */
int lines, chars, x; /* count of lines and characters */
FILE *in; /* input file stream pointer */
in = fopen("d5.dat", "r");
if (in == NULL) {
perror("fopen: d5.dat");
exit(1);
}
fgets(buf, 11, in);
while(!feof (in)) {
for(x = 0; buf[x] != '\0'; x++)
if(buf[x] == '\n')
lines++;
if(isalpha(buf[x]))
chars++;
}
fclose(in);
printf("\nLines:%d\nCharacters:%d\n\n", lines, chars);
return 0;
}