Thread: Where to put files to be read in on a Mac

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    15

    Where to put files to be read in on a Mac

    OK this is more of a logistics question than anything. I'm running XCode on my Macbook right now and can't figure out how to read in a file in my program.

    Basically there is a pixel_load.dat file that needs to be read in the program.

    Code:
    #define FILENAME "pixel_load.dat"
    
     //Start of main function
     int main(void)
     {
        // declarations
    	 FILE *pixel_load = NULL;
    	 int i, num_measurements, N;
    	 double displacement_pixels[MAX_VALUES], load[MAX_VALUES];
    
     
        pixel_load = fopen(FILENAME, "r");
    	if(pixel_load == NULL)
    	{
    		printf("Could not open data file\n");
    		return -1;
    	}
    My professor said something about you can put a file in a certain spot so that you don't have to put a path to the file in the #define part. Where might that be on a Mac?

    Also I tried just putting it in my program's folder right beside the main.c file and putting that path (my path was something like "\\Users\\JakeeStoltz\\Photograph\\pixel_load.dat" ) in the #define part but that didn't seem to work..

  2. #2
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126

    Wink :)

    If you don't specify any path you should write (and also read) from the highest position in your hard disk.

    in your case :

    Leopard/pixel_load.dat

    where Leopard is the name of your hard disk primary partition.

    Cheers

    BTW: If you use cocoa framework I would use
    [[NSBundle mainBundle] pathForResource:@"pixel_load" ofType:@"dat"];
    in order to get the path of your file wich it should be in the folder as your Xcode project.
    Mac OS 10.6 Snow Leopard : Darwin

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    It may need to be in the same folder where the executable is. Instead of where the source is. Possibly a debug or release subfolder if it's anything like Microsoft's environment.

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    15
    Quote Originally Posted by nonoob View Post
    It may need to be in the same folder where the executable is. Instead of where the source is. Possibly a debug or release subfolder if it's anything like Microsoft's environment.
    Bingo! I put it right next to the executable and that seemed to be the trick. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  3. Read In From Many Files In One Function
    By djwicks in forum C Programming
    Replies: 12
    Last Post: 03-24-2005, 07:39 AM
  4. read from .txt file & put into array?
    By slow brain in forum C Programming
    Replies: 6
    Last Post: 02-25-2003, 05:16 AM