Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: 8TrackRobot on February 25, 2017, 03:51:17 pm

Title: .txt File is not saving in the desired directory (Mac)
Post by: 8TrackRobot on February 25, 2017, 03:51:17 pm
I am learning C programming so I'm a total beginner.

I am using Code::Blocks 12.11 on Mac, I have got Xcode and downloaded the command line packages so everything seems to be doing what I want it to.

My problem is when I open a .txt file it doesn't appear in the directory with the source code and other files, I have found it in the All My File folder in Finder.

I am creating projects using the following steps > File > New > Project > Console Application > Then naming the Project and saving it to a File I  have created for all my programmes.

All my previous projects are saved in neat folders in this directory except the .txt file.


This is my code.


/**

ACS126 - Problem Sheet 2.Q2
Project: Opening a Text File for Writting
Author: Craig McAllister
Date: 23.02.17

**/

#include <stdio.h>

main()
{
      FILE *myFile;
      myFile=fopen("first.txt","w"); // open first.txt for writing (or create it if it doesn't exist) - this will be in the same folder as the c program
      fprintf(myFile,"Hello World!!!\n");
      fclose(myFile);
}
Title: Re: .txt File is not saving in the desired directory (Mac)
Post by: stahta01 on February 25, 2017, 04:10:37 pm
I believe your problem maybe a Mac Operating System or C Programming issue.

The only likely CB issue is the working directory is NOT being set correctly.
What does the project have set for working directory?

Likely under
Project -> Properties...
Tab: Build Targets
Box: Execution Working Directory

Tim S.
Title: Re: .txt File is not saving in the desired directory (Mac)
Post by: 8TrackRobot on February 25, 2017, 04:37:29 pm
Thanks for responding :)

It doesn't have anything just a dot   .

I have included a screen shot

Craig