I have a task to read matrix from .txt file and then make an 2D array in C. I read numbers well but I have a problem with writing these numbers into array because I need to allocate memory because im not sure how big the matrix will be.

```
int read()
{

   FILE *f;
   int number, i, j, size;

   f = fopen("matrix.txt","r");
   if (f == NULL)
   {
      printf("Error reading matrix.txt\n");
      return 1;
   }

   printf("Sucess! \n");
   fscanf(f, "%d",&size);
   printf("Size of matrix: %d\n", size,size);

   int* matrix;

   matrix = malloc(size * sizeof(int));

   for(; feof(f) == 0;)
   {
        for(i = 0; i < size; i++)
        {
            for(j = 0; j < size; j++)
            {
              fscanf(f,"%i",&number);
//          *(*(matrix+j)+i) = number; 
              printf("%i\t",number);
            }
        printf("\n");
        }
   }
   fclose(f);

```