I have a data file in .txt
format with 7 rows and 4 columns.
I am using following code to read these values:
#include<stdio.h>
#include<math.h>
int main()
{
int N=7, i;
double x[7], y[7], p[7], q[7];
FILE *f1;
f1=fopen("data.txt","r");
for(i=0;i<N;i++)
fscanf(f1,"%lf %lf %lf %lf", &p[i], &q[i], &x[i], &y[i]);
fclose(f1);
}
Here N is the number of rows in the data file, which I know in advance.
Is there any way to read the number of rows in the data file, so that I can generalize this code for any data file without knowing the value of N in advance.
NOTE: The number of columns is not changing between different data files.