Home | News | Documentation | Download

Problem reading file

Hi, I have a problem reading a file that I produce by using Map() on several root files. Everything is piped to a single txt file and the contents of Map() display 5 columns. when trying to read them I only get the first letter or number of the information en each column of each line.

using namespace std;
#include<iostream>
#include<fstream>
#include<cstring>
#include<stdio.h>
#include<cstdlib>

const char Loadzombie(const char *zombieList);

enum {
  trash   = 0,
  trash2  = 1,
  trash3  = 2,
  here    = 3,
  trash4  = 4,
  };


void check2(){
  Loadzombie("/home/danny/Documents/PHD/omega_ana/old_asym_code/modular_all_sigX/omega_volatile/submissions/check_job_runs/zombielist.dat");  
}

const char Loadzombie(const char *zombieList){
    FILE *fplist,*fpfile;              //file pointers for filelist and each file therein
    Char_t lline[250];                 //for reading in lines from filelist
    Char_t fline[250];                 //for reading in lines from file
    Char_t filename[250];              //file
    Int_t  fcount=0;                   //counter for no of files read in
    Int_t  chancount=0;                //counter for no of channels read in
    Char_t zombieTable[30];  

    
    if((fplist=fopen(zombieList,"r"))==NULL){ //open filelist
      cerr << "Error Couldn't open file: " << zombieList << endl;
      return -1;
    }
    fcount=0;       
     
      cout << zombieList << endl;
      
      chancount=0;                                             //starting array at 1 for consistency with E_ID
      while((fgets(fline,500,fplist)) != NULL){
	sscanf(fline,"%s"/*""%s %s %s %s %s"*/,
	       &zombieTable[trash],
	       &zombieTable[trash2],
	       &zombieTable[trash3],
	       &zombieTable[here],
	       &zombieTable[trash4]);
	//cout << zombieTable[trash]<< "  " << zombieTable[here] <<endl;
	chancount++; 
      }
	cout << zombieTable[0];
          fclose(fplist);
    
    return(0);

}

Thanks.

Hi,

I am not sure I get the question. This program does not seem to use ROOT. I suggest to start from one of the many C++ tutorials online in case of issues.

Cheers,
D