The objective is to write an int function that returns the number of occurrences of numbers greater than 100 in a text file. The function should receive the file pointer as an argument.
Here is my code so far:
#include <stdio.h>
int function(FILE *infp);
int main ()
{
FILE *infp;
printf("\n%d\n",function(infp));
}
int function(FILE *infp)
{
int num, counter=0;
if ((infp = fopen ("text.txt", "r")) == NULL)
printf ("\ncannot open the file text.txt\n");
while ((num = getc())!=EOF)
{
if (num>100)
counter++;
}
fclose(infp);
return (counter);
}
It is always outputting 0. I'm thinking either getc is not the right command to use here or maybe I am formatting the text file wrong? Any help would be great