title: Unable to get File I/0 working in period counter function -c
body: <pre><code>int periodCount(const char *filename) {
      FILE * fp;
      int n = 0;
  
      if( (fp=fopen(filename,"r")) != NULL) {
          while(fgetc(fp)!= EOF) {
              if(fgetc(fp)=='.') n++;
              fclose(fp);
          }
      }   
      return n;
  }
  </code></pre>
  
  <p>Here is my code, it simply should count the number of periods in the file named filename, which contains 15 periods, yet when I try to print 'n' at the end of the program, it seems to only be reading 1 of the periods. I know that the problem is probably within the while loop, but I'm not sure why it's doing it.</p>