Programming C on Xcode

Joined
Jan 23, 2012
Messages
1
Reaction score
0
Points
1
I have a C program that among many things I want it to read the input from a file and write it in another file. The problem with the input file and the output file is the same. Unless I write the whole path for the file, it does not recognize the fopen instruction.

I will include the piece of code so I can explain myself better: If I write:
PHP:
outfile = fopen("UnifE-n51-k5", "w");
fprintf(outfile,"a \t b \t ajuste \t media \n");
fprintf(outfile,"==================================\n");
nothing happens and the address for the outfile is NULL.
However if I give the entire path for the file
PHP:
outfile = fopen("/Users/Marta/Documents/VRPStochastic/UnifE-n51-k5", "w");
fprintf(outfile,"a \t b \t ajuste \t media \n");
fprintf(outfile,"==================================\n");

Works fine. I know I can do this all the time, but I do write a lot of code for my academic research and I don't want to remember the entire path for every program. Besides my colleague works on Windows and if I get part of his code I have to change it to adjust it to Xcode, which is a waste of time.

Thanks a lot for your help.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top