Creat a disk File?

Discussion in 'Mac Programming' started by Fritzables, Jan 15, 2012.

  1. macrumors regular

    Joined:
    May 6, 2011
    Location:
    Brisbane AUSTRALIA
    #1
    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.

    Pete
     
  2. macrumors 6502a

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #2
    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.
     
  3. thread starter macrumors regular

    Joined:
    May 6, 2011
    Location:
    Brisbane AUSTRALIA
    #3
    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.

    Pete
     
  4. macrumors 603

    Joined:
    Aug 9, 2009
    #4
    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.
     

Share This Page