Sophie
Sophie

Reputation: 69

Reading Data File in C

I am using Xcode version 3.1.3 to edit and compile C programs. When I attempt to read a .dat data file, it does not work, although the program works fine on a Linux machine.

I placed the data file into the build folder of the project. I have no idea why it doesn't work. This is the code:

#define courseFile "course.dat"

FILE * in; /*FILE pointer to do the stream IO*/
    in = fopen(courseFile, "r+");

Upvotes: 1

Views: 456

Answers (1)

JerryLetter
JerryLetter

Reputation: 45

I got a temporary work around answer from dougpan on stack overflow. This is what he said.

That's a good question... I have a temporary, work around, answer... I do respect your request to focusing on the question rather than your code. As a quick temporary answer, the only answer I have for you at this point is to modify your code, for now, if you are only debugging your code along with your data file. I know hard coding your file locations is a no-no but for debugging purposes the following will get you over this bump in your road. You can try to hard code the directory location along with your data file so that your code can find it. For example, let's say that your Users directory on your Mac is jerryletter, you could copy your Data.txt file to your Users directory ~/jerryletter. Then could modify just one line of your code like the following:

strcpy(file_name,"/Users/jerryletter/Data.txt");

Therefore, it is an Xcode IDE problem. See my reasons and the answer here: https://stackoverflow.com/a/24266915/3565426

Upvotes: 1

Related Questions