EDIT: The problem has been solved.
I'm trying to read a file that is located in proc/PID/environ which is 5 folder higher in the tree of folder than my current program.
I can do it when I write the following file name "../../../../../proc/PID/environ", but I would like the program to be more portable (compatible) with other computers.
The file is not recognized when I use "/proc/PID/environ", which is the absolute path of the file.
Here is the lines of code where it seems to not work:
int main(int argc, char *argv[]) {
char filename[32];
char* value;
int key = 579;
char line[1000];
int nDigits = floor(log10(abs(key))) + 1;
snprintf(filename, nDigits+15, "/proc/%d/environ", key);
FILE *file = fopen(filename, "r");
The error is simply that the file doesn't exist. Error : errno='No such file or directory'.
filename
if printed is really /proc/579/environ
so I don't see the problem
Is there a way to read a file in C that is not in the current directory, without using ".." to go back in the tree? /proc/PID/environ
being at the root of the tree, I would like to be able to use the absolute path.