I am reading a text file of two-column numeric data. I do not know the number of rows that the file will contain. Currently, I read the file twice: Once to ascertain the length and the second time to fill the arrays with the data. Is there a way to create and populate the arrays while only having to read the text file once?
Here is my current code:
Thanks for your time.
double tempx, tempy;
fid = fopen("c:/file.txt","rt");
while( fscanf(fid,"%le%le", &tempx, &tempy )!= EOF )
rewind( fid );
x = new double[i];
y = new double[i];
while (fscanf(fid,"%le%le", x+i, y+i)!= EOF)