Greetings all,
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:
[code]#include
#include
#include
using namespace std;
void printf_oddity(){
string datafile;
ifstream filelist (“Input_files.txt”);
if (filelist.is_open())
{
while (! filelist.eof() )
{
getline (filelist,datafile);
cout << datafile << endl;
}
filelist.close();
}
else cout << “Unable to open file”;
string fname1=datafile+".root";
cout << fname1 << endl;
//
printf("\n",datafile);
printf(" Filename = %s \n",datafile);
printf(" Filename = %s \n",fname1);
printf("\n",datafile);
}[/code]
The output I get from root when the script is run in interpreted form is as follows:
[quote]root [0] .x printf_oddity.C
ru980309_r01
ru980309_r01.root
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
and in
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
Regards