开发者

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 File开发者_运维技巧s\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?


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");


Make sure you double up the \ characters. The string you're passing in should be "Saurabh\\pqrs.txt". Note that beginning a path with \\ means that it's not relative. (Well, actually it's relative to your current drive, but I doubt that's what you're looking for.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜