title: Malloc for struct in C
body: <p>so I have to do a c program that reads a text file, stores it in a struct with an extra value (the average) and output the struct with fread into a new struct. However the information isnt going anywhere. I'm almost positive its the malloc don't know how to allocate the proper amount of memory (C++ and Java kinda spoiled me there)</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  typedef struct student {
      int id;
      float marks [10];
      float gpa;
  } Student;
  
  int main (){
      FILE *inFile, *bin;
      int i, sum, sLength;
      char input[45];
      char newLine;
      inFile = fopen ("Assign6.dat","r");
      bin = fopen ("Assign6out.dat","wb+");
      Student current;
  
  //  while (!feof(inFile)){
          sum = 0;
          fgets (input,sizeof(input), inFile);
          sLength = strlen(input);
          sscanf (input, "%d\n", &amp;(current.id));
          for (i = 0; i &lt; 6; i++){
              sscanf (input, "%lf", &amp;(current.marks[i]));
              sum += current.marks[i];
          }
          current.gpa = sum / 6;
          fwrite (&amp;current, sizeof (Student), 1, bin);
  
  //  }
      fclose(inFile);
      Student newer;
      fseek (bin, 0, SEEK_SET);
      fread (&amp;newer, 1, sizeof(Student), bin);
      fclose(bin);
      printf( "%d, %.1lf\n", newer.id, newer.marks[0]);
  }
  </code></pre>
  
  <p>So the input file is this</p>
  
  <pre>
  122456 1.0 2.0 3.0 4.0 5.0 6.0
  </pre>
  
  <p>and the output is</p>
  
  <pre>
  122456, 0.0
  </pre>
  
  <p>can anyone help me on this please? I looked around but couldn't really find anything that fit for me.</p>
  
  <p>First Post so be nice please!</p>