943,829 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3154
  • C++ RSS
May 16th, 2006
0

Directory and folder

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
yuzhang is offline Offline
43 posts
since May 2006
May 16th, 2006
0

Re: Directory and folder

Quote originally posted by yuzhang ...
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.
Reputation Points: 39
Solved Threads: 24
Junior Poster
dubeyprateek is offline Offline
176 posts
since Mar 2006
May 16th, 2006
0

Re: Directory and folder

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,951 posts
since Aug 2005
May 16th, 2006
0

Re: Directory and folder

thanks dragon
Reputation Points: 10
Solved Threads: 0
Light Poster
yuzhang is offline Offline
43 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Dynamic Boolean Array in VC++.net 2003
Next Thread in C++ Forum Timeline: finding max value of 10 integers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC