C++ Xcode file location help!

Discussion in 'Mac Programming' started by Inconsequential, Nov 3, 2008.

  1. macrumors 68000

    Joined:
    Sep 12, 2007
    #1
    Basically this is for my aero eng course, so no changing coding language ;)

    Im trying to open a file from where Xcode stores the executable, IE in the debug folder.

    Code:
    	/* open file for input */
    	inf=fopen("datafile.txt","r");
    Reads it from my home folder (Where the docs folder etc is).

    I would like it to read from the Debug folder in the project folder.

    I've tried a few things but with no success.

    Anyone help?

    Cheers!
     
  2. macrumors 6502

    Berlepsch

    Joined:
    Oct 22, 2007
    #2
    Did you try something like

    fopen ("/this/is/the/path/to/my/Debug/file.txt", "r")​

    yet?
     
  3. macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #3
    When in doubt, print out your current working directory at runtime to see where it's set.
     
  4. thread starter macrumors 68000

    Joined:
    Sep 12, 2007
    #4
    Edit: Ok, thats weird!!

    Now it works with the full path where it didn't yesterday!!!

    Oh well, all is good now.

    Thanks people :)
     

Share This Page