File open with fopen() fails when I provide a relative path. I am running this code on a windows machine with Visual Studio 2010.
const char* OUTPUT_FILE = "output/PERFORMANCE.txt";
FILE* f = fopen(OUTPUT_FILE, "w");
Is this way of specifying relative path incorrect? Should I be using “\” separator?
Specifying the absolute path using the same format works fine. (e.g “C:/output/PERFORMANCE.txt”)
Check what directory you are currently in. With Windows there are at least two ways:
_getcwdGetCurrentDirectoryMake sure you are in the directory you think you are, and make sure that the directory
outputexists in the directory, otherwise you’ll need to create it. With Windows, there are at least two ways:_mkdirCreateDirectoryThe file will fail to open (even for writing) if any intermediate directories are not present. The file may also fail to open if you do not have permissions to the target directory.