title: Read File to Dynamic memory
body: <p>I am trying to read a file, assign the values to the structure members and then add the values into a dynamic memory allocation. I used a for loop to read all the values and then add them to the dynamic array. It gives me errors while I compile it.</p>
  
  <p>How could I assign the values to the Structure members and at the same time add them to a dynamic array? </p>
  
  <p>I would really appreciate your assistance !! thanks. </p>
  
  <p>Here is my code</p>
  
  <pre><code>struct Student
  {
      char *name[20];       
      char *gender[10];     
      int   age;           
      char *course[20];       
  };
  
  struct elements 
  {
      struct Student *s;
      struct elements *next;
  };
  
  FILE *file;
  char c;
  char type[30];
  
  int main(int args, char *arg[])
  {
      struct Student *school = (struct Student *)malloc(sizeof(struct Student)); // Dynamic array
  
      file = fopen(arg[1], "r");  // reading file
  
      if(file != NULL)
      {
          while((c = fgetc(file)) != EOF) putchar(c);
          {
              int size;
              int r;
              for (r=0; r&lt;size;r++)
              {
                  fscanf("Name: %s", school-&gt;name);
  
                  //school-&gt;name = Addstudent(); // didn't work
                  //printf("names are: %s\n",school-&gt;name); // here I want to make sure the value name is in the array
              }
           }
      }
      else 
      {
          printf("Unable to open file \n");   
      }
      free(file);
      return 0;
  }
  
  char* Addstudent()
  {
      char* name;
      fscanf(file, "Name: %s",type ,name);
      return name;
  }
  </code></pre>
  
  <p>Here are the Errors</p>
  
  <blockquote>
    <p>In function ‘main’: Latest1.c:59:4: warning: passing argument 1 of
    ‘fscanf’ from incompatible pointer type [enabled by default]
    /usr/include/stdio.h:449:12: note: expected ‘struct FILE *
    <strong>restrict</strong>’ but argument is of type ‘char *’</p>
    
    <p>Latest1.c:59:4: warning: passing argument 2 of ‘fscanf’ from
    incompatible pointer type [enabled by default]
    /usr/include/stdio.h:449:12: note: expected ‘const char *
    <strong>restrict</strong>’ but argument is of type ‘char **’</p>
    
    <p>Latest1.c:59:4: warning: format not a string literal and no format
    arguments [-Wformat-security]</p>
  </blockquote>