title: Reading a file in C and store data in arrays
body: <p>My code below reads a file in C.It displays the file, the average score, maximum score,and the names of all the students who earned the maximum score. The exam scores(0-100 format to 1 decimal place and use a field width of columns) are stored in an array and the names(name and last name limited to 15 characters) are stored in a 2-dimensional array of characters that is parallel to the scores array. My problems are:</p>
  
  <p>1) The code doesn't read(print) the file properly (I think is related to fscanf and the arrays).</p>
  
  <p>2) My two functions don't print the results.</p>
  
  <p>Any suggestion is appreciated, thanks.  </p>
  
  <pre><code>#include "tools.h"
  #define MAX 30                  // Maximum number of students
  int computeMax(double stSco[], int numSt);  // Gets the average and highest
                                              // score
  void outputBest(double num[], char nameHg[][15], int hgPl, int totStu);
  
  int main()
  {
      double score[MAX];
      char name[MAX][15];
      char fileName[80];
      int k, count = 0, hgCt;
      stream dataFile;
      banner();
      printf("Type the name of file you want to read\n");
      scanf("%79[^/n]", fileName);
      dataFile = fopen(fileName, "r");
      if (dataFile == NULL)
      {
          fatal("Cannot open %s for input", fileName);
      }
      while (!feof(dataFile))
      {
          fscanf(dataFile, "(%lg,%s)", &amp;score[k], &amp;name[k]);
          printf("%6.1f %s\n", score[k], name[k]);
          count++;                // It counts how many students there are
      }
      hgCt = computeMax(score, count);    // Stores the value sent by the
                                          // function
      outputBest(score, name, hgCt, count);
      fclose(dataFile);
      bye();
      return 0;
  }
  
  int computeMax(double stSco[], int numSt)
  {
      int k, maxScore = 0, sum = 0;
      double maximum = 0, average = 0;
  
      for (k = 0; k &lt; numSt; k++)
      {
          sum += stSco[k];        // It sums all scores
          if (stSco[k] &gt; maximum)
          {
              maximum = stSco[k];
              maxScore = k;       // Stores the index of the maximum score
          }
      }
      average = sum / numSt;
      printf("The average score is %d\n", average);
      printf("The maximum score is %d\n", maximum);
      return maxScore;
  }
  
  void outputBest(double num[], char nameHg[][15], int hgPl, int totStu)
  {
      int k;
      for (k = 0; k &lt; totStu; k++)
      {
          if (num[k] = hgPl)
          {                       // It finds who has the highest score
              printf("%s got the highest score\n", nameHg[k]);
          }
      }
  }
  </code></pre>