Supernovah
Supernovah

Reputation: 2045

Opening file in another directory in C

How is this achieved? I want to use

pFile = fopen( file, "rb" );

Where file is a char, string or long containing the literal text containing a local path to a binary file

C:\Documents and Settings\Supernovah\Desktop\Supernovah.bin

but of course that crashes.

I am also interested in how to recur over the current directory in a portable way. windows.h is a little ugly but if I can't do it in a portable way. So be it.

thanks :)

Upvotes: 1

Views: 22331

Answers (2)

Clifford
Clifford

Reputation: 93476

Both GCC/MinGW and VC++ 2008 (and probably others) allow Unix style path delimiters in Win32. so:

char* file="C:/Documents and Settings/Supernovah/Desktop/Supernovah.bin";

would work as well, and is portable between operating systems. Spaces in paths however may be problematic, requiring replacement with %20 in Linux.

Upvotes: 2

CDR
CDR

Reputation: 8408

char* file="C:\\Documents and Settings\\Supernovah\\Desktop\\Supernovah.bin";
FILE* pFile = fopen( file, "rb" );

Upvotes: 5

Related Questions