-
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.
-
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?
-
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
-
Or use an absolute path to the file in your program.
-
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?
-
File name doesn't matter.
Todd
-
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
-
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