title: How to read floats from file in c?
body: <p>I am struggling with reading floats from a file which I created during the program lifetime. I was trying to rewind the file, I was trying to open and close file before reading it, I was trying to put values directly in the table and by another variable. Idk what can I do more, what's wrong here?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  int main(void) {
      srand(time(NULL));
  
      float *tab;
      float x = 0.0;
      int i, size;
      FILE *fp;
  
      fp = fopen("data.txt", "w+");
      if (fp == NULL) {
          printf("Error");
          system("PAUSE");
          exit(1);
      }
      printf("Size of table: ");
      scanf("%d", &amp;size);
  
      tab = (int*)malloc(size * sizeof(int));
  
      for (i = 0; i &lt; size; i++) {
          tab[i] = (8.0 - 2.0) * (float)rand() / RAND_MAX + 2.0;
          fprintf(fp, "%.2f ", tab[i]);
      }
      for (i = 0; i &lt; size; i++) {
          printf("%.2f ", tab[i]);
      }
      printf("\n");
  
      fp = fclose;
      fp = fopen("data.txt", "w+");
      tab = realloc(tab, 2*size);
  
      for (i = 0; i &lt; size * 2; i+=2) {
          fscanf(fp, "%f", &amp;x);
          printf("%.2f ", x);
          //tab[i + 1] = tab[i] / 2;
      }
  
      /*for (i = 0; i &lt; size * 2; i++) {
          printf("%.2f \n", tab[i]);
      }*/
  
  
      fp = fclose;
      printf("\n");
      system("PAUSE");
      return 0;
  }
  </code></pre>