Name for saving a canvas

I have this piece of code to write a canvas to a pdf-file, where spigot_to_plot is a short int(let’s say 8 ):

		TCanvas * c  = new TCanvas("c", s.Data(),  1500, 800);
		c->Divide(5,3);
		for(unsigned int jj = 0; jj<14; jj++){
	  		c->cd(jj+1);
	  		c->Update();
	  		TPad * pad = (TPad*)gROOT->GetSelectedPad();
	  		f->getSecModGraphs(true,spigot_to_plot,jj+1,pad);

		}	
                    char testcanvas[20];
  		
 		sprintf(testcanvas,"testcanvas(%d).pdf",spigot_to_plot);             
	  		cout<<"Name  is "<<testcanvas <<endl;
  			c->SaveAs(testcanvas);

I want to give this file the name “testcanvas(8).pdf”. This is also what I get in the terminal from de cout. But the file which is created is just named “testcanvas”. What’s the problem here?
Thanks

The SaveAs method has some special control characters for multi-page PDFs and things like that. Have you tried escaping the parentheses with ( and )?

See here: http://root.cern.ch/root/html/TPad.html#TPad:Print@1

[quote=“jfcaron”]The SaveAs method has some special control characters for multi-page PDFs and things like that. Have you tried escaping the parentheses with ( and )?

See here: http://root.cern.ch/root/html/TPad.html#TPad:Print@1[/quote]

do you mean sprintf(testcanvas,"testcanvas\(%d\).pdf")? When I try this I get an error when I try to build:"error: unknown escape sequence ‘)’ " en when I use “testcanvas(%d).pdf” it builds but I get the same result as before.

I’m just guessing here, so a real ROOT expert can confirm/deny, but it’s possible that you just can’t use (N) in the filenames with SaveAs, because ROOT uses that as syntax for multi-page files. You could try saving the file using a dummy name, then using gSystem->Rename to rename it.

Jean-François

There was a bug in the pad saving which has(?) been fixed in the latest versions, see thread [url=https://root-forum.cern.ch/t/escaping-characters-when-saving-plots/16447/1 Characters when Saving Plots’[/url], especially post [url=https://root-forum.cern.ch/t/escaping-characters-when-saving-plots/16447/1