View Full Version : Help with C programming: inputting files into code

Mar 5, 2009, 11:01 PM
Hey all

I do a bit of c programming for school and tried out xcode, played around a bit and finally figured stuff out, wrote my code, ran it, it works fine.

However, when i try to load a file to my code, it wont load in xcode....i have complied it in terminal and works fine

the file is called data.txt and IS in the same directory (remember it works fine with terminal)

g++ filename -o programname, it works fine....

anyone know how to load the file into xcode, i have tried my best...please check out the screenshot as well....

Mar 5, 2009, 11:26 PM
Xcode sets the current working directory differently. By default it is the build directory, so unless your file is in that folder, it won't work. If you go to the Executables group, then double-click your target's executable you can change the working directory to something else. Or just use absolute paths.

Mar 6, 2009, 01:24 AM
^ wow thanks, that worked perfect double clicked on executables and under general chose project directory instead of build products directory. can u explain the absolute path a bit more?

Mar 7, 2009, 06:01 PM
What he means by absolute paths is that there is a designated path in which the file uses.

So your User's directory has this absolute path:


So what you can do instead of copying the file into your directory, you can just type in the path. I forget how Xcode reads the path of the file...

So in your C program where you define the file name you can do this instead:

file = "~/Documents/ThisIsTheFileIamWorkingWith.txt";

Or something of the sort.

Mar 8, 2009, 02:16 PM
^oh that's absolute paths...I should have known that, thanks for clearing it up....makes a lot more sense.

Thanks for your input!!!!