Fail reading a file. Maybe EOF?

Hi
I have some kind of problem with reading from a file. The file looks like this:

gas molecular viscosity [Pa.s] *
1.8e-5
gas data: 0 (mean free path), 1 (density) *
1
gas: mean free path [m] / density [kg/m^3] *
1.2
number of steps*
30
Particle Diameters [nm] *
4.159582
4.4981
4.864167
5.260026
5.688101
6.151014
6.651599
7.192924
7.778304
8.411323
9.095858
9.836104
10.636592


I´m interested in saving the diameters into an array. For this, I read the number of lines of the file and substract the number of lines until "Particle Diameters [nm] *", so that I know the number of different diameters there are (since there can be any number).

The code I have used is the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
int main (void)
{
	char line[256];
	double data[500];
	
    int i, j, k, t, n;
	double P, T, Qa, Qsh, Lt, Dt, Mg, dvsg, mfpg, rhog, Kn, Cc;	
	double Dp[500], Diff[500], tau[500], Pn[500];

	FILE *FH0;
	char* echofile;
	echofile="output_data.txt";
	
 	FH0=fopen(echofile,"w+");
	if (FH0==NULL)
	{
		printf("Error: echofile could not be opened\n");
		exit(1);
	}

	ifstream indata;
	indata.open("input_data.txt");
	if (! indata.is_open()) 
	{
		fprintf(FH0,"Error: inputfile could not be opened\n");
		exit(1);
	}

    //read the number of lines and calculates the number of diameters
    ifstream file( "input_data.txt" ) ;    
    string liness ;    
    vector<string> lines ;        
    while( getline( file, liness ) ) 
           lines.push_back( liness ) ;
    
    int totlines = lines.size();
    int top = totlines - 9;	

	fprintf(FH0,"total lines\t \t %i\n",totlines);
	fprintf(FH0,"read lines\t \t %i\n",top);    
    fprintf(FH0,"\n");   
     
	for (i=0;i<4;i++) //reads the singly-line data after the *
	{
		indata.getline(line,256,'*');
		fprintf(FH0,line);
		fprintf(FH0,"\n");
		indata >> data[i];
		fprintf(FH0,"%g",data[i]);
	}
	
    n=0; 
    fprintf(FH0,"\n\n diameters read \n");    	
    
     
       
       while (!indata.eof()); 
      {
              for(t=1; t<=top; t++)
              {  
                 n++; 
                              
                  indata >> data[9+t]; 
                //  indata.ignore(top,'\n'); 	 
                  
              
                  // particle diameter [nm -> m]
             Dp[t-1] = data[9+t]*1.0e-9;  
             fprintf(FH0,"%d\t %g\n",n, Dp[t-1]);  
            } 
        }
        
          
         

      indata.close();  
  



The way it is done is not working, I guess it cannot find the EOF, and if I remove the "while (!indata.eof());" (yes, I know I shouldn´t! ;)) the diameters it shows are totally wrong :
diameters read
1 2.64231e-317
2 3.19859e-317
3 3.75487e-317
4 4.31114e-317
5 5.28469e-317
6 6.39725e-317
7 7.5098e-317
8 8.62236e-317
9 1.05695e-316
10 1.27946e-316


Could someone tell me where is my fail?

Thanks in advance!
Topic archived. No new replies allowed.