0

Consider a line of simple C code:

fopen("C:\\project\\test1.dat","r");
it "directs" the program to the directory where it can find the file from which it will read.

My question is under what circumstances, I may write
fopen("test1.dat","r") instead?

Does the program need to be in the same folder / directory as test1.dat?

Thanks

3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by yuzhang
0

Consider a line of simple C code:

fopen("C:\\project\\test1.dat","r");
it "directs" the program to the directory where it can find the file from which it will read.

My question is under what circumstances, I may write
fopen("test1.dat","r") instead?

Does the program need to be in the same folder / directory as test1.dat?

Thanks

If you use fopen("test1.dat","r") which is the typical usage (no path information given), fopen will look in the current working directory. This the directory where your project file (.dsw in case of VC++ 6.0 and .sln in case of VC++ 7.1) is present. If u run your programe from explorer, say by clicking on it, current woring directry is one in which .exe of your application is present.

0

In addition, if the file is NOT one the current working directory the program may have to change the current working directory to where the file is. There are a few operating systems where there is no concept of "current working directory", in which case the program has no choice but to specify the full path.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.