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

shaffman2001

macrumors newbie
Original poster
Dec 17, 2009
2
0
I'm having trouble reading my text files using xCode. Here's part of my code:

Code:
//I initialized fileName as a char array earlier.
	printf("What is the name of the file? ");
	scanf("%s", fileName);
	
	//Make LinkedList to make linked list of Players
	fp = fopen(fileName, "r");

	if(fp == NULL)
	{
		printf("Dang it!\n");
		printf("I entered \"%s\"\n", fileName);
		return 1;
	}

I think I know why it's not working. After searching the forums, I've read xCode puts my text files in a different directory than my .c file. Thing is, I don't know where to put my text file so my program can read it. Can I move them in xCode somehow, or do I need to put them somewhere in the project folder?
 
Xcode sets the working directory. In the Groups & Files table, open the Executables group and right-click your project's executable and select Get Info. In the General tab at the bottom you'll see the "Set the working directory to" fields. Put your file there. Or just use absolute paths.
 
In the "Project Menu" select the last item named "Edit Active Executable <Your Executable Name>"

In the resulting dialog select the "General" tab-view.

At the bottonm of the dialog, in the radio button group titled "Set the working directory to:", select project directory.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.