Re: fopen
Re: fopen
- Subject: Re: fopen
- From: Scott Ribe <email@hidden>
- Date: Mon, 02 Jul 2012 12:52:59 -0600
This is basically a "UNIX runtime environment" question. And the answer is: what your application's working directory is set to, depends on how your application is launched, and you should not (indeed, can not) count on it. You have to either use full paths, or set the working directory yourself, or inspect your environment to find out what it is.
That said, when you are running under Xcode, it will be the folder where your executable is located. So you *can* count on it for testing & learning, just not for actual production code.
On Jul 2, 2012, at 11:11 AM, rckrueger wrote:
> I am just learning c, and this is a beginner's question. I am using Xcode 4 (Command Line tool) to create a program that will read a simple text file (a number 1234). When I use the code:
>
>
> #include <stdio.h>
>
> int main(int argc, const char * argv[])
> { FILE *inputfile; // a pointer to the input file
>
> inputfile = fopen("test.txt", "r");
>
> to find and open the test.txt file which I have in the Project folder, same level as the main.c file, I get the error message:
> Thread 1: EXC_BAD_ACCESS (code=1, address=0x68
> which I guess means that it can't find the file.
>
> When I use this line to look for the file on the desktop:
> inputfile = fopen("/users/robertkruegertiger/desktop/test.txt", "r");
>
> the program works as expected.
>
> How do I get the program to find the test.txt file in the Project folder. I have already used the "Add Files to FileReadExample..", which copied it from the Desktop folder to the same folder as the main.c code. What more needs to be done? TIA
>
> postscript: And when the program finds the file and works properly, will it automatically write subsequent files in the same folder?
--
Scott Ribe
email@hidden
http://www.elevated-dev.com/
(303) 722-0567 voice
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >fopen (From: rckrueger <email@hidden>) |