I have been trying to create a function to count the number of lines of code. This is what I have come up with, but it is getting stuck in an infinite loop.
int numberoflines(char filename[]){
FILE *file = fopen(filename, "r");
int count = 0;
int ch = 0;
while( EOF != (ch = getchar())){
if(ch == '\n'){
count++;
}
}
return count;
}