save ".txt"

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 :frowning:

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…

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

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!

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