Search code examples
cfopen

Do I need to specify the path of my file in the fopen function?


FILE *fopen(const char *filename, const char *mode);

I saw that some people only put the name of the file inside the "filename" part, some others put the entire path

example

FILE *fopen("mytext.txt", r);

FILE *fopen("/myfolder/mytext.txt", r);

which is the correct one?


Solution

  • If the file is in current directory when you run the program - no.

    If it's not - yes, you will need to specify the path (absolute or relative to current directory)