For loop over histograms

I have a problem with creating hstack. I have a bunch of histograms in different .root files and I want to add them. I know how to do that, but because there is so many of them and they all look like zmumu1.root, zmumu2.root etc, I would like to make a for loop. As I am fairly new to programming, I found a piece of program from that should work, I got some ideas from couple posts here, and tried to make it work for me:

   char zmumu[14];                                                         
   for(Int_t i=1; i<13; i++){
    sprintf(zmumu, "%s%d","zmumu",i);
   TFile *zmumu = TFile::Open("zmumu[i].root");
   TH1F *h = (TH1F*)gDirectory->Get("h_muon0_pt");                                             

(Not that I would really understand it. To be honest, I have no idea what sprintf ought to do.) I keep getting error message “Error in TFile::TFile: file zmumu[i].root does not exist”. Apparently, it does not do anything. Any ideas how to solve this?
Thank you very much.


THStack *h0 = new THStack("h0", "my stack");
for(Int_t i = 1; i < 13; i++) {
  TFile *f = TFile::Open(TString::Format("zmumu%d.root", i));
  if ((!f) || f->IsZombie()) { delete f; continue; } // just a precaution
  TH1F *h; f->GetObject("h_muon0_pt", h);
  if (!h) { delete f; continue; } // just a precaution

Thank you very much, that’s perfect!