Why I can'f fill a variable into a histogram?

Hi, Rooter,

This seems a simple problem but I’m stuck here.
I can print out the variable “temperature”, but have no idea why it can’t be filled into a histogram ?
The “temperature” should be 131.000, however in the histogram the value of temperature is zero.

Thanks a lot in advance !
My code is here [1].

Best,
Junhui

[1]


void asking()
{
   Float_t         temperature;
   TString filename = "asking.root";
   TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
   dir.ReplaceAll("asking.C","");
   dir.ReplaceAll("/./","/");
   FILE *fp = fopen(Form("%stry.txt",dir.Data()),"r");
   Int_t nlines = 0;
   TFile *hfile = new TFile(filename,"RECREATE");
   TH1F *htemperature = new TH1F("htemperature","This is the temperature distribution",100,-5,5);

   char line[301];
   while (fgets(&line,300,fp)) {
      sscanf(&line[0],"%f ",&temperature);
     // printf("temperature = %8f \n", temperature);
      htemperature->Fill(temperature);
      nlines++;
   }
   printf(" found %d points\n",nlines);
   fclose(fp);
   hfile->Write();
}

Your histogram range is -5 5. if, as you claim, temperature = 131 you are filling out of this range … it is normal you get an empty distribution.

Thanks a lot for your comment ! , couet, =D>
By myself, maybe I won’t figure that out for ever, :blush: !!!

Please tag my post as solved !