how to read 2d array from a file in c

#include <stdio.h>

#define MAX_ROWS 100
#define MAX_COLS 100

int main() {
    FILE *file;
    int rows, cols;

    // Open the file for reading
    file = fopen("your_file.txt", "r");

    // Check if the file is opened successfully
    if (file == NULL) {
        printf("Error opening the file.\n");
        return 1;
    }

    // Read the dimensions of the 2D array
    fscanf(file, "%d %d", &rows, &cols);

    // Declare a 2D array
    int array[MAX_ROWS][MAX_COLS];

    // Read the elements of the 2D array from the file
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            fscanf(file, "%d", &array[i][j]);
        }
    }

    // Close the file
    fclose(file);

    // Rest of your code goes here

    return 0;
}