Based on our conversation in the comments, you have several alternatives, which I'll list below from, IMHO, most to least desirable.
You never specified if you were in Windows, GNU+Linux, or were doing cross-platform development, but I'm sure you can adapt the suggestions to your platform.
Multiple and Custom Config Files (Recommended)
You could modify your program to look at your platform's standard location for program data and/or configuration files. For example, you could have it look for a standard config at /etc/<your-program>/default.conf
in GNU+Linux or %APPDATA%\<your-program>\default.conf
in Windows.
If different users need to use their own personal configs, the program could also be made to accept a config file path as an argument. For example:
GNU+Linux:
$ ./your-program --config ${HOME}/.your-program/my.conf
Windows:
> your-program.exe --config %userprofile%\your-program\my.conf
Note that the use of %userprofile%
may change based on Windows versions and/or shells used (e.g. standard cmd.exe vs powershell).
Compiling in the Path (Not Recommended)
Based on your comments, a short-term workaround could be to compile the absolute path into it for the __FILE__
macro to give that back to you at runtime. As I said in my comment:
if you're completely sure about the program always being placed in the same directory for everyone, then you can set the absolute path shown by the __FILE__
macro if you send the full path when compiling; e.g. gcc $(pwd)/your-file.c
, when it prints __FILE__
will show the full path it had at compile time, not run-time. (Can't add enough disclaimers here, though)
Please note that there're many reasons to not use this approach. I'm simply suggesting it as a short-term workaround to pull out of an existing crisis-level situation you may have, while you (hopefully) take a closer look at the more desirable approach to handle configurations and path-finding.