Daq_root.cpp:94: error: expected unqualified-id before ‘for’

Hi,

I get the error when I try to compile the code:

char hadcname[40];
char htdcname[40];

TH1I *hadc = new TH1I[16];
TH1I *htdc = new TH1I[16];

for(int iloop=0; iloop<16; iloop++){

sprintf(hadcname,“adc_channel_%d”,iloop);
sprintf(htdcname,“tdc_channel_%d”,iloop);

hadc[iloop] = new TH1I(hadcname,"",4096,0,4095);
htdc[iloop] = new TH1I(htdcname,"",4096,0,4095);
}

line 94 is the begining of the for loop.

Could anybody point me the error?

Regards,
supriya

do:

[code] {
char hadcname[40];
char htdcname[40];

TH1I *hadc[16];
TH1I *htdc[16];

for(int iloop=0; iloop<16; iloop++) {

  sprintf(hadcname,"adc_channel_%d",iloop); 
  sprintf(htdcname,"tdc_channel_%d",iloop); 

  hadc[iloop] = new TH1I(hadcname,"",4096,0,4095); 
  htdc[iloop] = new TH1I(htdcname,"",4096,0,4095); 

}

}[/code]

Rene

Hi Rene,

I did this. (In fact I tried this before) but this still gives me the following error

daq_root.cpp:94: error: expected unqualified-id before ‘for’
daq_root.cpp:94: error: expected constructor, destructor, or type conversion before ‘<’ token
daq_root.cpp:94: error: expected constructor, destructor, or type conversion before ‘++’ token

Regards,
supriya

Could you post your code as attachment?
Can you run the code that I posted?

Rene

here it is
daq_root.cpp (8.29 KB)

Hi,

In C++ you can only have declaration outside of a function. So you must move your for loop (around line 94) inside a function (the main function is likely the best place).

Cheers,
Philippe.

Great! It works now!

Thanks Philipe

supriya