Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kegriffin

macrumors newbie
Original poster
Aug 31, 2007
1
0
I'm using Xcode for a C programming class, and while most of it is over my head, a lot of the features are really helpful. I'm a little puzzled about fopen, though. When I try this

fp = fopen("inventory.data", "r");

fp (which is a FILE*) is 0 during debugging. However, if I use the full path (/Volumes...) it works. I'm required to upload and compile my code on the school's servers, so using those paths is inconvenient. I've put the inventory.data file in my project folder along with the source files, and have added it under the source section in Xcode. Is there some way I can reference the file like this?
 
Does relative files work i.e. fopen("./inventory.data" ...
or use #defines

Code:
#define MAC_OS_X

#ifdef MAC_OS_X
#define INV_FILE /Volume/.../inventory.data
#else
#define INV_FILE inventory.data
#endif

There is a bit better way ...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.