Q:

Read numbers in file and find Median C

I am constructing a C program which prints Fibonacci numbers into a file and finds the median.
The output I am getting is a very large and incorrect number. Any insight would be great.
Median Function C
   int findMedian(FILE *file, int size)
   {
      int medianPos, medianVal, readVal, count;
      medianPos = (size / 2);
      count = 0;

      while(fscanf(file,"%d", &readVal)==1)
      {
         if(medianPos == count)
         {
            medianVal = readVal;
         }
         if ((medianPos += 1) == count)
         {
            if(size % 2) //This means that it is even
            {

            }
            else
            {
               medianVal += readVal;
               medianVal /= 2;
            }
         }
         count++;
      }
      return medianVal;
   } 

File
1 1 2 3 
5 8 13 21 
34 55 89 144 
233 377 610 987 
1597 2584 4181 6765 

Output
The Fibonacci median: -1576638118

Function Call
median = findMedian(Fibonacci, size);

A:

Your 'count' variable is not initialized. So it is possible that your if conditions will not be met and your medianVal remain uninitialized too.

