The usage of vector type in ROOT

void readMyFile()

   FILE * f=fopen("EnergyList.txt", "r");
   char line[20];
   int i;
   float d;
   while (fgets(line,20,f)) {
      sscanf(&line[0] ,"%d,%g",&i,&d);
      printf("%d %g\n",i,d);

Alright. I checked sscanf, gets, open methods, but this code seem to read only 1st number of the floats in the text file. Are you sure, it reads them precisely as they are.

Are you structure the floating numbers as one integer + the decimal point? Is that the reason you put %d,%g in sscanf?

On number from the input file: 1,38E-02

Ref: C library function - sscanf()

In C/C++, floating point values are required to use a “dot” (i.e., “1.38E-02”), not a “comma” (i.e., not “1,38E-02”).

BTW. This is a ROOT forum; there are other forums dedicated to C/C++.

1 Like

I see my excel uses , not . for decimal point. I totally missed that. That’s where I took my input.

I read two values because your file looks like a csv one. If you have only one value
make sure to use dot instead of command and change de code to read only one value.