how to format a .txt file in working directory so it can be opened and read on Mac in CLion C executable

Answered

I have put the .txt file in the same directory and reconfigured the working directory to the and it still doesn't work the code works and can open .txt files using other IDE's

0
8 comments

Hello! CLion looks for input files and writes output files to the "generation path" folder (cmake-build-debug by default, can be set in File | Settings | Build, Execution, Deployment | CMake | Generation path). If you put your input file in this folder, CLion will be able to open it. Or you can just try setting an explicit path like C:/<path_to_file>/data.txt in input_file.open().

1
Avatar
Permanently deleted user

@Anna Falevskaya its very strange CLion can see the file and opens the file but then the program crashes straight away leaving an error code 6 can any one send screen shots of a simple code in c and the file formatting that opens a file because I  think iv tried everything.

0
Avatar
Permanently deleted user
0

I am using Linux, not Mac. When I use FILE *fp=fopen("filename.txt",w); it works but I do not know where it is (as the following field (Generation path) does not exist: File | Settings | Build, Execution, Deployment | CMake | Generation path). When I use FILE *fp=fopen("/home-directory/filename.txt",w); (home-directory is any directory which I created after my home), the open file fails (return null).

0

>as the following field (Generation path) does not exist: File | Settings | Build, Execution, Deployment | CMake | Generation path

It's now called "Build directory".

0

After using Build Directory to select a directory which I created, /project-directory/debug (thanks for the tip), and executing FILE *fp=fopen("filename.txt",w); ...; fprintf(fp, "%f ", src_rotation[i]); fclose(fp); the directory .../debug is still empty. Again why FILE *fp=fopen("/project-directory/filename.txt",w); should fail?  

0

Hi William!

Sorry for the delay. Did you run your project? The file should be created next to the executable, in the Build Directory.

0

Please sign in to leave a comment.