Tuesday, March 25, 2008

Why can I only access a file when running in the debugger?

If you are using relative paths such as in
FILE *file;
file = fopen("data.xml", "r");
the working directory may be the problem. The debugger may be setting up the working directory differently than Windows sets it when you execute the program. Windows will set the working directory to be the same as the directory of the executable, unless if it is launched by a shortcut. A shortcut will set the working directory according to its "Start in" parameter. If this parameter is empty, Windows will set the working directory to be the current user's home folder (under Documents and Settings in Windows XP).

No comments: