I am trying to write a file to open a file and read the contents of that file in C. I am using xcode but the file pointer returns a value null.
int main(int argc, char** argv)
{
FILE *fp;
fp=fopen("input.txt","r");
if (fp==NULL)
printf("error");
}
This shows error as the output. Could someone help me to find the right place to put the file input.txt in the project?
The file would need to go in the “current directory” where the program is launched. This is configurable. In the “Groups and Files” pane, expand “Executables” and pick your executable. Press Command-I to open the info window. Near the bottom of the “General” tab, you can select the current directory for when the application is launched.