View Full Version : Creat a disk File?
Jan 16, 2012, 01:56 AM
I want to write some data to a disk file. Nothing major, just ASCII data to a 'txt' file.
Would I just use the good ol'e 'fout' as you would in 'C' or is it best to use NSOutputStream?
I am using XCode4 and Cocoa.
Jan 16, 2012, 02:33 AM
Where is the data? If it's in an NSString or NSData object, then those classes contain routines to write the data to a file.
If the data isn't in an Objective-C class, then I would probably end up writing the data using normal C stdio routines.
Jan 16, 2012, 02:56 AM
The data is within a SQLITE3 database.
I am writing a HAM Radio Contest Logging app and when the contest is complete one needs to submit a LOG of all contacts as an ASCII file as proof.
Jan 16, 2012, 12:11 PM
Break the problem down.
First, get the data out of the sql database.
If it's in C string form, then you already have it in a form you can used fprintf() on.
If the data isn't in C strings, what form is it in? Simple C types like int or float? You can still use fprintf().
If the data is in NSString or NSNumber form, then look at those classes and find methods that convert to C strings (for NSString) or simple C types (for NSNumber). Then you can use fprintf().
SInce Objective-C is a superset of plain ordinary C, you can use every C function the same way. If you already know C's stdio functions, then save yourself the trouble and just use what you know.