[ROOT] errot in reading array of files

From: Michael Wiesmann (wiesmann@e18.physik.tu-muenchen.de)
Date: Fri Oct 11 2002 - 20:45:00 MEST


Dear Subhendu!


Maybe you allocate the FILE pointer in the wrong way.

 
 > FILE *fp[0];

            ^^
What you probably want to have are two FILE pointers, therefore you
have to allocate

FILE *fp[2];

> fp[0] = fopen("pt1.dat","r");
 > 
 > FILE *fp[1];

.. and leave this ^ line out:



In your cae you allocate first an array with 1 pointer
(*fp[0]) and after that another filepointer array (*fp[1]) which leads
to conflicts.



Btw, root is based on c++ and provides nice function for file
operations with streamers. Have a look in a c++ book under iostream
and fstream.


Michael

> fp[1] = fopen("pt2.dat","r");
 > 
 > 
 > for(Int_t j=0;j<2;j++){
 > for(Int_t i=0;i<m;i++)
 >    {
 > fscanf(fp[j],"%f",&x[i]);
 > fscanf(fp[j],"%f",&y[i]);
 > fscanf(fp[j],"%f",&w[i]);
 > fscanf(fp[j],"%f",&z[i]);
 > fscanf(fp[j],"%f",&v[i]);
 > if(y[i]<0)
 >       {
 > ny[i]=-y[i];
 >        }
 > else ny[i]=y[i];
 > 
 > 
 >    }
 > 
 > TGraph *gr[j] = new TGraph(m,ny,z);
 >  
 >  gr[j]->SetLineColor(j+1);
 >   gr[j]->Draw("AC");
 > 
 >   fclose(fp[j]);
 >                      }
 >   }
 > ******************************************************************
 >  
 > can anybody help?
 > Thanks in advance.               
 >         Subhendu Chakrabarti   
 > 
 >                 
 > 
 > 
 > 
 > 
 > 
 > 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:14 MET