I have incorporated the code snippet that Axel linked to in his response to one of my earlier posts into one of my scripts and I have encountered what appears to be an oddity with printf.
The short script to illustrate the problem is as follows:
using namespace std;
ifstream filelist (“Input_files.txt”);
while (! filelist.eof() )
cout << datafile << endl;
else cout << “Unable to open file”;
string fname1=datafile+".root"; cout << fname1 << endl;
printf(" Filename = %s \n",datafile);
printf(" Filename = %s \n",fname1);
The output I get from root when the script is run in interpreted form is as follows:
[quote]root  .x printf_oddity.C
Filename = ░°K☺ru980309_r01
Filename = ↑¢1☻↑¢1☻_r01.root[/quote]
If I try to compile the script I get a seg-fault.
The file “Input_files.txt” just contains the string “ru980309_r01”.
The string “datafile” seems to be read correctly and the string “fname1” seems to be created correctly - but they are interacting strangely with the printf command.
Any guidance on why this is happening and how I can correct it would be greatly appreciated.
Problem found in
ROOT 5.24/00 (trunk@29257, Jun 30 2009, 09:23:51 on win32)
CINT/ROOT C/C++ Interpreter version 5.17.00, Dec 21, 2008
ROOT 5.17/04 (trunk@20359, Nov 16 2007, 19:13:00 on linux)
CINT/ROOT C/C++ Interpreter version 5.16.26, Oct 11, 2007