views:

116

answers:

2

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 :)

+4  A: 
char* file="C:\\Documents and Settings\\Supernovah\\Desktop\\Supernovah.bin";
FILE* pFile = fopen( file, "rb" );
CDR
thnks very much :D
Supernovah
What about if I wanted to take user input for it? (console app)
Supernovah
User input is not a problem because it is entered at rintime. The string does not literally contain the \\, but a single \ character, the \\ is simply a way of escaping the compiler's special treatment of escape sequences in string literals and character constants.
Clifford
+1  A: 

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.

Clifford