tags:

views:

27

answers:

2

Hi i created one sample application that saves data as text file using simple c (FILE) function . I am using below code

FILE *fp = fopen("Log.txt", "w");
fprintf(fp,"%s\t %s\t %s\t %s\t %s\t\n","Id","Type","MacId","IPAddress","Version");
fclose(fp);

When i run this code in simulator.There is a Log.txt file in Macintosh HD folder.Then i can able to view the text file log.When i run this in device ,Where it can store .txt file and how can i view this text file ? Is it possible ?

Thanks in advance...........

+1  A: 

save the file to the documents-directory.

NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *fullPath = [docDir stringByAppendingPathComponent:@"Log.txt"];

edit:

FILE *fp = fopen([fullPath cStringUsingEncoding:NSUTF8StringEncoding], "w");
fluchtpunkt
After doing this, use the Xcode Organizer to download the contents of the app's document folder from the device.
Robot K
My application crashes when i use fprintf line in xcode
Tamil
This line crashes fprintf(fp,"%s\t %s\t %s\t %s\t %s\t\n","Id","Type","MacId","IPAddress","Version");my application
Tamil
did you convert fullPath to a CString before you used fopen?
fluchtpunkt
A: 

As mentioned by fluchtpunkt, Documents directory is the place where you can put your files. Simplest way to do it is perhaps creating NSString instance and then call writeToFile:atomically:encoding:error: method. Check NSString documentation for details.

Matthes