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?