Error - please help

Hi all,

I would like to get a histogram from a .dat file, but ROOT returns with the following error message (see below with the red colored text):

FILE *fp=fopen("P.dat","r+");
TH1F *hist_1 = new TH1F("histogram","distribution",100,0,1);
hist_1->Sumw2();
hist_1->SetFillColor(48);
Double_t j=0.0;
while((fscanf(fp,"%lf",&j)!=EOF)){printf("the value read is %lf\n",j);hist_1->Fill(j);hist_1->Draw();}

The error:
[color=red]
Error: fscanf param[0]=0 must not be 0 (tmpfile):1:
*** Interpreter error recovered ***
[/color]

Please help me to solve this! What is wrong? Thank you in advance!

Hi,

Most likely the file does not exist. Use:FILE *fp=fopen("P.dat","r+"); if (fp==0) { fprintf(stderr,"Error: Could not open P.dat!\n"); return; } TH1F *hist_1 = new TH1F("histogram","distribution",100,0,1); hist_1->Sumw2(); hist_1->SetFillColor(48); Double_t j=0.0; while((fscanf(fp,"%lf",&j)!=EOF)){printf("the value read is %lf\n",j);hist_1->Fill(j);hist_1->Draw();}

Cheers,
Philippe.