I'm using a new mac with macOS Monterey and the M1 Max chip. I'd like fopen
to default to the current directory when no path is given (this is what I'm used to and I think is the norm), but it's defaulting to my user folder. So, for example, when I compile the below code, the resultant app, regardless of where it is, will only open file.txt if that file is in my user folder (I get a segmentation fault if it's anywhere else). Similarly, if I have the code make a new file with FILE* fp = fopen("new file.txt", "w");
, the new file will appear in my user folder.
I'm compiling with gcc (that I had downloaded via downloading the newest version of Eclipse) from Terminal with the command:
gcc -std=c99 main.c -o yo
When I build using Eclipse or leave out -std=c99
I have the same issue.
Also, for gcc --version I get:
InstalledDir: nathanschmidt@nathans-MacBook-Pro ~ % gcc --version Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include/c++/4.2.1 Apple clang version 13.0.0 (clang-1300.0.27.3) Target: arm64-apple-darwin21.3.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE* fp = fopen("file.txt", "r");
printf("%d\n", fp);
int x;
fscanf(fp, "%d", &x);
fclose(fp);
printf("%d\n", x);
return EXIT_SUCCESS;
}