Author Topic: .txt File is not saving in the desired directory (Mac)  (Read 5422 times)

Offline 8TrackRobot

  • Single posting newcomer
  • *
  • Posts: 3
.txt File is not saving in the desired directory (Mac)
« 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);
}

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: .txt File is not saving in the desired directory (Mac)
« Reply #1 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline 8TrackRobot

  • Single posting newcomer
  • *
  • Posts: 3
Re: .txt File is not saving in the desired directory (Mac)
« Reply #2 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