Where does fopen open a new file?

9 views (last 30 days)
Elisa Michelini
Elisa Michelini on 13 Jan 2018
Hi everybody. I wrote a simple function in Matlab: it simply uses fopen and fprintf to open and write inside a text file (for example "file_name.txt"). Then I used Matlab Coder to generate a Dll containing this function and I tested it in Visual Studio (version 2017). No errors were showed and the .exe file has been correctly built. But, where I can find the "file_name.txt", after having run the executable? How can I test that the Matlab function has been called and the file "file_name.txt" has been created? Thank you in advance for your answers!

Answers (1)

Darshan Ramakant Bhat
Darshan Ramakant Bhat on 16 Jan 2018
If you are using MATLAB function directly without the dll, fopen() will create the file in the current directory. If the dll is used in Visual studio, then the fill might be created in the current execution path. However, to avoid the ambiguity, one can specify the full / relative path as the file name argument. This should created the file in the specified directory. Please refer the following documentation: https://www.mathworks.com/help/matlab/ref/fopen.html#btrnibn-3
To check the current execution path in the Visual studio refer the below stack overflow link:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!