title: How Can Read Values from File, store them in a structure and find their average, sum, product etc... using C
body: <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;conio.h&gt;
  #include&lt;windows.h&gt;
  
  #define SIZE 1024
  
  typedef struct rational
  {
      int  numerator;
      int denominator;
      struct rational *next;
  }rational;
  
  double add_rationals(rational*);
  void multiply_rationals();
  void subtract_rationals();
  void divide_rationals();
  void read_data(FILE*, int[], int*);
  void display_values(rational*);
  rational * createList(int []);
  
  int main()
  {
      system(&quot;cls&quot;);
  
  
      FILE* ifp;
      ifp = fopen(&quot;file.txt&quot;, &quot;r&quot;);
      int data[SIZE] ={0};
      int sz = SIZE;
      
      read_data(ifp, data, &amp;sz);
      
      printf(&quot;\nRead Integer Count:%d\n&quot;, sz);
  
      rational* HEAD = createList(data);
      display_values(HEAD);
   
      /*
          want to start after the 1st number because 1st number is size of arr
          data[0] is the 1st number we just read from the text
      */
  
      //display_values(HEAD, data[0]); // passing data[0] as size cuz the 1st number is size
  
  
  }
  
  
  
  // double add_rationals(rational* r)
  // {
  //     rational* c;
  //     c = r;
  
  //     static double x = 0 , y = 0, sum;
  //     x = r-&gt;numerator;
  //     y = r-&gt;denominator;
  
  //     while(c-&gt;next != NULL)
  //     {
  //         sum = x/y + add_rationals(r-&gt;next);
  //     }
  
  //     return sum;
      
  // }
  
  rational * createList(int data[])
  {
      rational *head = NULL;
      rational *temp = NULL;
      rational *p = NULL;
      rational *r = NULL;
      int count = 0;
      
      for (int i = 1; i &lt; 5; i++)
      {
          temp = (rational*)malloc(sizeof(double));
          temp-&gt;numerator = data[i];
          temp-&gt;denominator = data[++i];
          
          temp-&gt;next = NULL;
  
          if(head == NULL) // Checking if the List has started yet
          {
              count++;
              head = temp;
              printf(&quot;\nHEAD NUMERATOR: %d, HEAD DENOMINATOR: %d\n\n&quot;, head-&gt;numerator, head-&gt;denominator);
          }
          else
          {
              p = head;
              while (p-&gt;next != NULL)
              {
                  count++;
                  p = p-&gt;next;
  
              }
              p-&gt;next = temp;
              
          }
          
      }
  }
  
  
  
  
  void display_values(rational* HEAD)
  {
      rational* o = NULL;
      o = HEAD;
      while(o-&gt;next != NULL)
      {
          printf(&quot;\n\nNUM: %d, DEN: %d&quot;, o-&gt;numerator, o-&gt;denominator);
          o = o-&gt;next;
      }
      
  }
  
  void read_data(FILE* fptr, int d[], int*size)
  {
      *size = 0;
      while ((fscanf(fptr, &quot;%d&quot;, &amp;d[*size])) == 1)
          (*size)++;
      
  }
  </code></pre>
  <p>PROBLEMS&gt;&gt;&gt;</p>
  <ol>
  <li>I am unable to display all the elements from the linked list in the function <code>void display_values()</code> function</li>
  <li>The pre-requisites are like this .. take the 1st number from a text file and create an array of that size...
  Let me show you with example:
  2 5 2 6 7 being the integers in the text file</li>
  </ol>
  <p>I want to read the 2nd and 4th items to a struct as numerators and the 3rd and 5th as denominators
  I want 5/2 and 6/7 as rationals and do all these operations with them
  Like Add, Sub, Mul , Div...etc</p>