title: malloc + fgets dynamic allocation
body: <p>This is my code:<br></p>
  
  <pre><code>int main(int argc, char *argv[]){
      FILE *fp;
      char *tmp, *tmp2, *user, *pass, *line;
      printf("Inserire utente: "); scanf("%ms", &amp;user); /* scanf %ms alloca dinamicamente la memoria */
      printf("Inserire password: "); scanf("%ms", &amp;pass);
      line = malloc((strlen(user)+strlen(pass)) * sizeof(char)); /* DUBBIOOOOOOOOOO */
      fp = fopen("/home/pol/auth.txt", "r");
      if(fp == NULL){
          printf("Errore apertura file\n");
          return EXIT_FAILURE;
      }
      while(!feof(fp)){
          fgets(line, /* E QUI?? */ , fp);
          tmp = strtok(line, " ");
          tmp2 = strtok(NULL, "\n"); /* con fgets ultimo carattere è \n (se pwd=12 =&gt; 12\n) quindi devo tagliare prima di \n */
          if((strcmp(tmp,user) == 0) &amp;&amp; (strcmp(tmp2,pass) == 0)){
              printf("USER: %s - PASS: %s\n", tmp, tmp2);
              free(user);
              free(pass);
              return EXIT_SUCCESS;
          }
          else{
              printf("Utente o password errati o non presenti nel DB\n");
              free(user);
              free(pass);
              return EXIT_FAILURE;
          }
      }
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>I would like to know if:<br></p>
  
  <ol>
  <li>it is correct to write into <code>fgets</code> the value <code>sizeof(line)</code> or not. My doubt is that <code>line</code> contain a pointer so it is always 4 or 8 bytes...<br></li>
  <li><code>line</code> is right allocated?<br></li>
  </ol>