Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

thabandit

macrumors member
Original poster
Nov 10, 2007
34
0
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....
 

Attachments

  • Picture 1.png
    Picture 1.png
    150.7 KB · Views: 107

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 

thabandit

macrumors member
Original poster
Nov 10, 2007
34
0
^ 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?
 

LtRammstein

macrumors 6502a
Jun 20, 2006
570
0
Denver, CO
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:

/Users/thabandit

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:

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

Or something of the sort.
 

thabandit

macrumors member
Original poster
Nov 10, 2007
34
0
^oh that's absolute paths...I should have known that, thanks for clearing it up....makes a lot more sense.

Thanks for your input!!!!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.