title: Write data from file to struct on C
body: <p>I have a file from which I want to read data previously created by another program but I get an segmentation fault error. This is the programm.</p>
  
  <pre><code>typedef char Telemento[MAX_CHAR+5];
  
  typedef struct{
     Telemento arraycola[NUM_ELEM];
     int inicio;
     int final;
  }TCola;
  
  typedef char TNombreImpresora[MAX_NOM_IMPR];
  
  typedef struct{
     TNombreImpresora nombreimpresora;
     int numerodeficherosencola;
     TCola colaImpresora;
  }TImpresora;
  
  typedef struct{
     TImpresora impresora;
     int ocupado;
  }TCelda;
  
  typedef TCelda Tlistaimpresora[MAX_IMPR];
  
  
  
  int main(){
      FILE *fp;
      int i=0;
      Tlistaimpresora listaimpresoras;
  
  
  
      fp=fopen("test.bin", "r");
  
      while(feof(fp)==0 &amp;&amp; i&lt;4){
         fread(&amp;listaimpresoras[i].impresora, sizeof(listaimpresoras[i].impresora), (i+1), fp);
         listaimpresoras[i].ocupado=1;
         i++;
      }
      fclose(fp);
  
  
      return 0;   
  }
  </code></pre>
  
  <p>Thanks for your time. If anyone needs more info please tell me.</p>