News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

.txt File is not saving in the desired directory (Mac)

Started by 8TrackRobot, February 25, 2017, 03:51:17 PM

Previous topic - Next topic

8TrackRobot

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);
}

stahta01

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++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

8TrackRobot

Thanks for responding :)

It doesn't have anything just a dot   .

I have included a screen shot

Craig