how to read 2d array from a file in c
/*
File structure:
3
150 250 150 20
180 -240 -150 150
200 0 0 200
*/
typedef struct{
float r;
float a;
float b;
float c;
} sphere; //sphere parameter
FILE *fp;
fp = fopen("C:\\Users\\ASUS\\Documents\\Numerical Methods lab\\sphere projection\\read_values_of-sphere.txt", "r");
int n;
fscanf(fp, "%d\n",&n);
printf("%d\n",n);
sphere sp[n];
for(int i=0;i<n;i++){
fscanf(fp, "%f %f %f %f\n", &sp[i].r, &sp[i].a, &sp[i].b, &sp[i].c);
}
for(int i=0;i<n;i++){
printf("%f ", sp[i].r);
printf("%f ", sp[i].a);
printf("%f ", sp[i].b);
printf("%f\n", sp[i].c);
}