Directory and folder

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2006
Posts: 43
Reputation: yuzhang is an unknown quantity at this point 
Solved Threads: 0
yuzhang yuzhang is offline Offline
Light Poster

Directory and folder

 
0
  #1
May 16th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: Directory and folder

 
0
  #2
May 16th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,549
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1484
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Directory and folder

 
0
  #3
May 16th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 43
Reputation: yuzhang is an unknown quantity at this point 
Solved Threads: 0
yuzhang yuzhang is offline Offline
Light Poster

Re: Directory and folder

 
0
  #4
May 16th, 2006
thanks dragon
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC