I want to read the matrix from file and store it in an array. But the array is storing only the last value of matrix. Can anyone explain this please?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
    FILE *fp, *fp1;
    int n = 0, i, j, a[4][4], b[16];
    fp = fopen("Output.txt", "r");
    if (fp == NULL) {
        printf("\nError; Cannot open file");
        exit(1);
    }
    while (!feof(fp)) {
        i = 0;
        fscanf(fp, "%d", &n);//reads the file containing matrix
        b[i] = n;//this part is not working
        printf("%d\n", n);
        i++;
    }
    fclose(fp);
    fp1 = fopen("Output2.txt", "w");
    for (i = 0; i < 4; i++) {
        for (j = 0; j < 4; j++) {
            fprintf(fp1, "%d\t", a[i][j] * 2);
        }
        fprintf(fp1, "\n");//creates file of altered matrix
    }
    fclose(fp1);
    return 0;
}
 
    