karalis1
karalis1

Reputation: 225

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?

Upvotes: 1

Views: 626

Answers (1)

Romeo Ninov
Romeo Ninov

Reputation: 7225

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)

Upvotes: 2

Related Questions