Thread: XCode and files

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    37

    XCode and files

    I'm trying to write a program using files. I'm having a little trouble figuring out how to make a file that my program can read input from using Xcode. I also need to be able to write to a file but I am assuming that if i send output towards a file the file will be made and written to like it does if I'm writing on a linux compiler. If I am wrong about that help would be appreciated and I could use some help making a file to read from.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you stick to the standard functions (fopen etc), then I see no reason why it wouldn't work.

    The only trick would be working out what the IDE calls "the current directory" when you're running the code.

    What have you tried?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Place it in your Debug folder under the Project that you created. (Assuming your current Build is set to Debug. If your Build setting is Release, then put the file under the Release folder).

    Or, in other words, it goes in the same folder in which XCode places your executable.

    Todd

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Or use an absolute path to the file in your program.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    37
    What type of file would it need to be? I put a file called info.dat into the debug folder which would work on linux. Do I need a different file type for mac?

  6. #6
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    File name doesn't matter.

    Todd

  7. #7
    Registered User
    Join Date
    Jul 2005
    Posts
    31
    You could also, make a GUI for your application, or make your application read command-line arguments. This assumes that you are happy using the Cocoa Framework which is probably included in your Xcode project (if you used the 'Cocoa Application' or 'Foundation Tool' templates when you started).

    To use a GUI, have a look at the excellent 'Currency Converter' tutorial (the Cocoa hello world app).

    Alternatively, have a look at this blog post regarding extraction of command line arguments, http://unixjunkie.blogspot.com/2006/...-in-cocoa.html

    Cheers,

    Dan
    Last edited by boyfarrell; 12-13-2007 at 02:26 AM. Reason: typos

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    It should also be noted that Mac OS 9 and earlier used a colon (":") for a directory separator, I think. You're probably using Mac OS X, though -- I'm not sure if Xcode even runs on Mac OS 9. Probably not.

    Mac OS X uses a forward slash ("/") for a directory separator AFAIK, just like UNIX. It was based on UNIX, after all.

    http://en.wikipedia.org/wiki/Path_(c...erating_system
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Where to put files to be read in on a Mac
    By bassist11 in forum C Programming
    Replies: 3
    Last Post: 03-12-2009, 09:39 AM