title: How can a function return self-defined struct?
body: <p>I am trying to scan the input file inside a function, instead of scaning the inputfile in the main function. but seems like it doesn't work this way.
  I guess it's the problem of the inputfile pointer, I am not very familiar with using pointers</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  typedef struct 
  {
      char firstname[32],lastname[32];
      int age;
  }mandef;
  
  mandef scaninput(int rows,FILE *inputfile)
  {
      int i;
      mandef man[rows];
      for (i = 0; i &lt; rows; i ++)
      {
          fscanf(inputfile,"%s",&amp;man[i].firstname);
          fscanf(inputfile,"%s",&amp;man[i].lastname);
          fscanf(inputfile,"%d",&amp;man[i].age);
      }
      return man;
  }
  
  int main ()
  {
      FILE *inputfile;
      inputfile = fopen("input.txt","r");
      if (inputfile == NULL)
      {
          printf("Error: Unable to open input.txt.");
          return(1);
      }
      int i,rows;
      char x;
      fscanf(inputfile,"%d",&amp;rows);
      mandef man[rows];
      man = scaninput(rows,inputfile);
      return 0;
  }
  </code></pre>
  
  <p>I want the code works the same way as this code</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  typedef struct 
  {
      char firstname[32],lastname[32];
      int age;
  }mandef;
  
  int main ()
  {
      FILE *inputfile;
      inputfile = fopen("input.txt","r");
      if (inputfile == NULL)
      {
          printf("Error: Unable to open input.txt.");
          return(1);
      }
      int i,rows;
      fscanf(inputfile,"%d",&amp;rows);
      mandef man[rows];
      for (i = 0; i &lt; rows; i ++)
      {
          fscanf(inputfile,"%s",&amp;man[i].firstname);
          fscanf(inputfile,"%s",&amp;man[i].lastname);
          fscanf(inputfile,"%d",&amp;man[i].age);
      }
      return 0;
  }
  </code></pre>
  
  <p>input.txt looks like</p>
  
  <pre><code>2
  Mike Abc 18
  David Abc 17
  </code></pre>