I have a function with something like
FILE *file1 = fopen("testing.txt", "r");
I can't modify this line. However, if I make a file named "testing.txt" in, say /tmp
, would I be able to make the function load the file from /tmp
instead of it's own directory. (Maybe by modifying the PATH
variable?)
If the program doesn't change its own working directory, you could
cd
into/tmp
and simply run the program from there.That opens a file from your current working directory.
You can change the current working directory using
chdir
.See this.
This is using
C
code.You can also use
cd
.For example, go to the terminal:
Also,
cd ..
will make you go to the directory above, andcd
will make you go to the home directory.Also, if you do not have the program in the directory in which you have to compile it, you can use
cp
which copies file.Then you can go to that directory, and run it from there.
I would recommend you to take a basic linux tutorial like this.