Search code examples
cfile-iodefaultfopen

How can i set the default file I/O location


I want to create and write to a file in a specific location on my computer. I have a fairly large project going, so I will just post the part in which I am stuck on.

f = fopen(FileName, "w");

FileName = the variable that contains a file name that I am going to write onto.

The problem is that it's creating and storing this file in the same directory location as my project. I want to store it in a subdirectory called Individual that is located in that same directory. Any ideas?


Solution

  • You can solve in two methods:

    Method 1) Change directory (e.g. use chdir() method)

    Method 2) Add the path onto the start of the filename.