title: C - Find maximum value in array
body: <p>I'm working on a program here and I am accessing file input and am looping through an array of values in the file. However, it's not properly calculating the maximum value. Any help?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
  
  int header, i, j, cur_val, auction[50], sum = 0;
  int max = 0;
  
  FILE * ifp;
  
  ifp = fopen("input.txt", "r");
  
  fscanf(ifp, "%d", &amp;header);
  
  for (i = 0; i &lt; header; i++) {
  
      fscanf(ifp, "%d", &amp;cur_val);
      printf("%d\n", cur_val);
  
      for (j = 0; j &lt; cur_val; j++) {
          fscanf(ifp, "%d", &amp;auction[j]);
  
          printf("%d\n", auction[j]);
  
          max = auction[0];
          if (auction[j] &gt; max) {
              max = auction[j];
          }
  
      }//end j loop
  
      printf("Max: %d\n", max);
      printf("\n");
      //printf("Auction %d was sold for $%.2f!\n", i+1, );
      //sum+=max;
  
  }//end i loop
  
  fclose(ifp);
  
  
  return 0;
  
  }
  </code></pre>
  
  <p>Here's the file input:</p>
  
  <pre><code>5
  
  4
  
  100 500 250 300
  
  1
  
  700
  
  3
  
  300 150 175
  
  2
  
  920 680
  
  8
  
  20 10 15 25 50 30 19 23
  </code></pre>
  
  <p>The max values printed to the console are as follows: </p>
  
  <pre><code>300 700 300 920 23
  </code></pre>
  
  <p>The middle 3 work but not the first and last. Any idea why?</p>