title: Storing strings using fgets
body: <p>I have a file which contains information about films like this:</p>
  
  <pre><code>Film code
  Name
  Year of release
  Movie length(in minutes)
  The film producer
  </code></pre>
  
  <p>I have to read this info from a file and store that info into pointers. My code so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  typedef struct filmiab
  {
      int koodpk;
      char *nimed;
      int aasta;
      int kestus;
      char *rezi;
  } filmiab;
  
  int main()
  {
      filmiab *db;
  
      FILE *f1;
      f1 = fopen("filmid.txt", "r");
  
      db-&gt;nimed = (char*)malloc(sizeof(db-&gt;nimed) * sizeof(char));
      db-&gt;rezi = (char*)malloc(sizeof(db-&gt;rezi) * sizeof(char));
  
      while(1)
      {
          fscanf(f1, "%d ", &amp;db-&gt;koodpk);
          fgets(db-&gt;nimed, 100, f1);
          db-&gt;nimed = (char*)realloc(db-&gt;nimed, sizeof(char) * sizeof(db-&gt;nimed)); //gets more memory to store the strings
          fscanf(f1, "%d %d ", &amp;db-&gt;aasta, &amp;db-&gt;kestus);
          fgets(db-&gt;rezi, 100, f1);
          db-&gt;rezi = (char*)realloc(db-&gt;rezi, sizeof(char) * sizeof(db-&gt;rezi));
  
          printf("Filmi kood: %d\nFilmi nimi: %sAasta: %d\nKestus minutites: %d\nFilmi rezis66r: %s\n",
          db-&gt;koodpk, db-&gt;nimed, db-&gt;aasta, db-&gt;kestus, db-&gt;rezi);
          printf("\n");
      }
  
      return 0;
  }
  </code></pre>
  
  <p>It just goes into an infinte loop and only prints the last 5 lines. I know that when using fgets it replaces all the strings with the last 5 lines.
  But what can I do so it would store all the info and that so I could print them out (or just use them) in another function. And why does it go into an infinite loop ?</p>
  
  <p>EDIT:
  I have to use only the pointers that are created in the struct.</p>
  
  <p>EDIT2:
  Now both these lines
      fgets(db->nimed, 100, f1);
      fgets(db->rezi, 100, f1);
  store the required info and the blank spaces. What to do so it only stores the names of the films and the producers.</p>