Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fopen() with relative path

I am have a trouble in using fopen() with relative path. I wanted to use fopen like this:

fopen("\\Saurabh\\pqrs.txt");

i am getting filePointer as null.

The situation arose because I am trying to create a setup or deployment project which has to read files. The file paths chosen by default after user executes setup are C:\Program Files\Setup.. (where exe is dumped). So I dumped the files in the same folder and gave path(fixed path or hardcoded) to those files in the program.

If the user selects some other path for installation, the program fails.

Is there any way I can fix this?

like image 702
Saurabh Ghorpade Avatar asked Feb 23 '23 19:02

Saurabh Ghorpade


1 Answers

Two problems:

  1. You need to escape the backslash character. Write \\.
  2. You need to use a relative path. By starting a path with \\ you mean start from the root directory.

Putting these together, I think you should write:

fopen("Saurabh\\pqrs.txt");
like image 100
David Heffernan Avatar answered Mar 06 '23 17:03

David Heffernan