title: Pass array of struct and return array of struct using pointers - function
body: <p>I realize this question has been asked often but I still dont really understand how it works. I want to try and read my file into my structures, inside a function and pass the structures through pointers to the function. I am unsure about how to even write the function prototype. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  #define MAX 90
  #define STR 200
  #define MAXLEN 40
  
  struct human {
      char name[MAXLEN];
      char surname[MAXLEN];
      int age;
      float weight;
  };
  int main(int argc, char *argv[]) {
      char *dlim= " ", *end = "\n";
      char *string;
      string = (char *)malloc(sizeof(char) * STR);
      int i = 0, j = 0;
      struct human *man = malloc(sizeof(struct human) * MAX);
  
      FILE *fin = fopen("data.txt", "r");
      if (fin == NULL) {
          printf("Cannot open file\n");
          exit(0);
      }
      while (fgets (string, STR, fin)){
          read (string, &amp;man[i], dlim, end);
          i++;
      }
      fclose(fin);
  
      free(string);
      free(man);
  
    return 0;
  }
  
  struct human *man read(char *fstring, struct *man, char *div, char *end){
     int i=0;
     char *tok;
  
          tok = strtok(string, dlim);
          strcpy(man[i].name, tok);
  
          tok = strtok(NULL, dlim);
          strcpy(man[i].surname,tok);
  
          tok = strtok(NULL, dlim);
          man[i].age = atoi(tok);
  
          tok = strtok(NULL, end);
          man[i].weight = atof(tok);
  
     return man[i];
  
  }
  </code></pre>
  
  <p>Whats the function meant to look like? And am i correct in assuming that through the use of pointers, the struct will be automatically be updated in main, without needing to return something in the function?</p>
  
  <p>Can the function also return nothing (void), because the use of pointers will automatically pass onto main?</p>
  
  <p>Thank you!</p>