As can be seen, it has one commenting line and subsequent rows with numeric data. I have been trying to import this data in my C++ program, but have been facing issues. My current C++ program does not import this data well; I have tested this with a printf statement to see what values were being imported. My current source code looks as follows:
FILE *ifile;
ifile = fopen("/data/vault/ap817/Accretion/Umbrella_scripts/project_scripts/planetary_structure_params.txt","r");
if (ifile != NULL){
printf("printing m_range %lf", m_range_val); //this is to test the garbage value from the instantiation above
while (fscanf(ifile, "%lf %lf %lf %lf %lf\n", &m_range_val,&p_range_val,&T_range_val,&r_range_val,&rho_range_val) != EOF){ //fscanf returns the number of items read, nothing else. if it
m_range.push_back(m_range_val);
p_range.push_back(p_range_val);
T_range.push_back(T_range_val);
r_range.push_back(r_range_val);
rho_range.push_back(rho_range_val);
fscanf() will fail and return 0 (not EOF) on the first line. You really should check for success (result = 5), not a specific failure condition (result = EOF). If I remove the comment line at the time, the code works fine.
But why are you using fscanf() at all? It would be much safer and easier to do this with streams.
Here I used a class (or struct if you like) to hold the data for each line in the file.
Also, the comment lines are ignored by default since the non-numeric data will not satisfy the requirement. It would be better to specifically reject lines which commence with a '#'.