Let's say the compiled C binary is located at ~/bin/my_cool_c_program.out
and I have the following code:
FILE *file = fopen("helloworld.txt");
perror("Open helloworld.txt");
Now I face the problem, that the code creates the helloworld.txt
file in the directory where I'm executing the binary from and not relative from where the binary is located. So calling it from ~
results in the creation of ~/helloworld.txt
, but I want it to save it to ~/bin/helloworld.txt
. I tried replacing it with "./helloworld"
, but that didn't work, too. When I call from the ~/bin/
directory itself everything works as expected.
And why is it, that the first one results in perror
printing Permission denied
after the file gets created, while the second one prints Successful
?
NOTE: I do check for file == NULL
and so on. I just removed it for simplicity.