moka
May 27, 2009, 3:51pm
#1
Hi,
I am currently trying to save a simple .txt file from an OF xcode project but for some reason nothng happens. I do it like that:
FILE * pFile;
pFile = fopen ("myfile.txt","w");
if (pFile!=NULL)
{
fputs ("fopen example",pFile);
fclose (pFile);
cout<<"success"<<endl;
}
Even though it tells me success nothing is saved, the file is not in the data folder not anywhere else, any ideas? I tried it in the draw() and setup() loop but nothing worked
Thanks
EDIT:
okay it should be like this:
FILE * pFile;
pFile = fopen (ofToDataPath("myfile.txt").c_str(),"w");
if (pFile!=NULL)
{
fputs ("fopen example",pFile);
fclose (pFile);
cout<<"success"<<endl;
}
Still it’s really weird why it tells me success even though it didn’t work…
zach
May 27, 2009, 5:53pm
#2
are you on a mac ?? I suspect so.
If that’s the case know that the exe (executable) is three levels deep… the file you saved is there, it’s just inside of the package.
try this instead:
FILE * pFile;
pFile = fopen ( ofToDataPath("myfile.txt").c_str(),"w");
if (pFile!=NULL)
{
fputs ("fopen example",pFile);
fclose (pFile);
cout<<"success"<<endl;
}
ofToDataPath() appends …/…/…/data/ on macs, and data/ on pc / linux machines and c_str() converts it back to a char * which is what fopen wants (ofToDataPath returns a string).
can you try that and see if it helps?
take care,
zach
moka
May 27, 2009, 8:45pm
#3
hey zach, I allready fixed it on my own thanks.
I am on a mac yes!
by the way, wouldn’t it be possible to put the images i load with ofImage into the executable / app aswell (into the Recources folder?)
Thanks!
zach
May 28, 2009, 2:03am
#4
but that would make sharing code more difficult.
now, you can zip src and data folders and it should work on all platforms.
take care!
zach