Thread: How to set correct directory

  1. #1
    Registered User
    Join Date
    Jan 2010

    How to set correct directory

    Hello all,

    I'm writing a code that creates a couple of files and saves them. The problem is, when the files are created they are saved to the user's home folder(unless the directory has been set in Terminal and the program runs from the same Terminal window), but I need it to be in the folder that that the code is running from.

    This would be easy as long as it's on MY computer and I don't move the folder. However, I need it to work when it is running from someone else's computer when I send it to them.

    I'd greatly appreciate it if someone could help. Thanks.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    If you don't include any path, the files will be saved in the directory where the executable is run from.

    You should probably mention your OS.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Jan 2010
    My bad... I meant to include my system but didn't.

    I'm on Max OS 10.6, and since this if for school I'm writing it to run on other macs. When I run the executable directly by double clicking on it, it runs fine but the files are saved to the user's home directory.

    When I set the directory in Terminal by typing in "cd (drag and drop the folder that the executable is in)" and then "./(name of executable)" it saves the files to the same folder that the executable is in.

    Still looking for help!
    Last edited by baikal_m; 02-18-2010 at 11:00 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. optimising program
    By SONU in forum C Programming
    Replies: 1
    Last Post: 05-18-2008, 10:28 AM
  2. About current working directory
    By George2 in forum Linux Programming
    Replies: 3
    Last Post: 05-02-2007, 10:34 PM
  3. C help for network animator
    By fastshadow in forum Tech Board
    Replies: 7
    Last Post: 03-17-2006, 03:44 AM
  4. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM