How can I read files in C using xCode?

Discussion in 'Mac Programming' started by shaffman2001, Dec 17, 2009.

  1. shaffman2001 macrumors newbie

    Dec 17, 2009
    I'm having trouble reading my text files using xCode. Here's part of my 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?
  2. kainjow Moderator emeritus


    Jun 15, 2000
    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.
  3. lloyddean macrumors 6502a

    May 10, 2009
    Des Moines, WA
    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.
  4. shaffman2001 thread starter macrumors newbie

    Dec 17, 2009

Share This Page