Hi Valeriy, A precision about my mail yesterday. Your first test1.C will work correctly with: leafStr = "EMPNO/I:ENAME[40]/C:JOB[40]/C:MGR/I:SAL/I:DEPTNO/I"; test2.C will not work. Rene Brun Valeriy Onuchin wrote: > > Hi, > is it possible to fill tree with " a character string terminated > by the 0 character" ? > I tried the followng macros , but both gave wrong output. > What's I'm doing wrong? > Thanks. Regards. Valeriy > > /////////////////////////// test1.C /////////////////////////////////////// > { > typedef struct { > Int_t EMPNO; > char ENAME[40]; > char JOB[40]; > Int_t MGR; > Int_t SAL; > Int_t DEPTNO; > } EMP; > > static EMP emp; > > TString leafStr; > leafStr = "EMPNO/I:ENAME/C:JOB/C:MGR/I:SAL/I:DEPTNO/I"; > > //create tree > TTree *tree = new TTree("T","EMP table"); > tree->Branch("emp",&emp,leafStr.Data()); > > // filling > emp.EMPNO = 7369; > strcpy(emp.ENAME,"SMITH"); > strcpy(emp.JOB,"CLERK"); > emp.MGR = 7902; > emp.SAL = 800; > emp.DEPTNO = 20; > tree->Fill(); > > emp.EMPNO = 7499; > strcpy(emp.ENAME,"ALLEN"); > strcpy(emp.JOB,"SALESMAN"); > emp.MGR = 7698; > emp.SAL = 1600; > emp.DEPTNO = 30; > tree->Fill(); > > tree->Show(0); > tree->Show(1); > } > > /////////////////////////// test2.C /////////////////////////////////////// > { > typedef struct { > Int_t EMPNO; > char* ENAME; > char* JOB; > Int_t MGR; > Int_t SAL; > Int_t DEPTNO; > } EMP; > > static EMP emp; > > TString leafStr; > leafStr = "EMPNO/I:ENAME/C:JOB/C:MGR/I:SAL/I:DEPTNO/I"; > > //create tree > TTree *tree = new TTree("T","EMP table"); > tree->Branch("emp",&emp,leafStr.Data()); > > // filling > emp.EMPNO = 7369; > emp.ENAME="SMITH"; > emp.JOB="CLERK"; > emp.MGR = 7902; > emp.SAL = 800; > emp.DEPTNO = 20; > tree->Fill(); > > emp.EMPNO = 7499; > emp.ENAME="ALLEN"; > emp.JOB="SALESMAN"; > emp.MGR = 7698; > emp.SAL = 1600; > emp.DEPTNO = 30; > tree->Fill(); > > tree->Show(0); > tree->Show(1); > }
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:24 MET