title: C segfault while using fscanf to make array from datas in a file
body: <p>I already tried to find a solution to my problem but I didn't find it so I post it here.</p>
  
  <p>I want to read a file and then create <strong>two 1D arrays from the data I got</strong>.
  the file is like that:</p>
  
  <ul>
  <li>1st line: number of data to collect  </li>
  <li>other lines: data i want to get </li>
  </ul>
  
  <p><strong>Here is my file :</strong> </p>
  
  <pre><code>7
  1.  4.1
  2.  8.2
  5  19.5
  12 50
  20  78
  30  50.05
  50  5
  </code></pre>
  
  <p>7 is the number of line I want to get (I want all the lines from 1. to 50). </p>
  
  <p>The code I wrote return me a segmentation fault but I don't understand why.<br>
  <strong>Here is what I wrote :</strong>     </p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;math.h&gt;
      #include &lt;stdlib.h&gt; 
  
      int main(void)
      {
        /* DECLARATION OF CONSTANTS AND VARIABLES */
        FILE* fichier = NULL;
        double* x = NULL;
        double* y = NULL;
        int k,n = 0;
  
       /* OPENING FILE */
        fichier = fopen("donnees1.txt", "r+");
  
            if (fichier != NULL)
               {
                fscanf(fichier, "%d", &amp;n);
  
                /* creating dynamic array of x and y */
                x = malloc(n * sizeof(int));
                y = malloc(n * sizeof(int));
  
                if (x == NULL)
                   {
                    printf("failed to allocate.\n");
                    exit(0);
                   }
  
                for(k = 0; k &lt; n; k++)
                   {
                    fscanf(fichier, "%lf %lf", &amp;x[k], &amp;y[k]);
                    printf("%lf %lf\n", x[k],y[k]);
                   }
                /* Closing file */
                fclose(fichier);
               }
            else
              {
               printf("Cannot open the file.\n");
              }
  
        /* Freeing memory */
        free(x);
        free(y);
        return 0;
      }
  </code></pre>
  
  <p><strong>This is what the program is returning me :</strong>  </p>
  
  <pre><code>1.000000 4.100000
  2.000000 8.200000
  5.000000 19.500000
  12.000000 50.000000
  20.000000 78.000000
  30.000000 50.050000
  50.000000 5.000000
  Segmentation fault
  </code></pre>
  
  <p>Thank you for your help and for your attention !</p>