N
Nate
I am working on an Oakley parser and want to call an fopen function to
read in the log file. I can use this to read the file, but only if I
pass a "const char" variable to fopen. Since I would like the end
user to specify the name of the log file, I have a scanf in there to
allow the user to do so, but it isn't a const at that point. I have
seen reference to calls like static_cast, dynamic_cast and
reinterpret_cast in C that will allow me to convert to another type,
but I am having a little trouble using them.
This is what I tried, with no luck:
printf("Enter the log file name: ");
scanf ("%c", &filename);
reinterpret_cast <const char>( filename );
and get this error:
OakleyParser.cpp(14) : error C2440: 'reinterpret_cast' : cannot
convert from 'char' to 'char'
So VS.Net recognizes both as Char, but to use the char variable
‘filename' in fopen, I have to have a constant.
file_in = fopen(filename, "r");
OakleyParser.cpp(20) : error C2664: 'fopen' : cannot convert parameter
1 from 'char' to 'const char *'
Any ideas?
read in the log file. I can use this to read the file, but only if I
pass a "const char" variable to fopen. Since I would like the end
user to specify the name of the log file, I have a scanf in there to
allow the user to do so, but it isn't a const at that point. I have
seen reference to calls like static_cast, dynamic_cast and
reinterpret_cast in C that will allow me to convert to another type,
but I am having a little trouble using them.
This is what I tried, with no luck:
printf("Enter the log file name: ");
scanf ("%c", &filename);
reinterpret_cast <const char>( filename );
and get this error:
OakleyParser.cpp(14) : error C2440: 'reinterpret_cast' : cannot
convert from 'char' to 'char'
So VS.Net recognizes both as Char, but to use the char variable
‘filename' in fopen, I have to have a constant.
file_in = fopen(filename, "r");
OakleyParser.cpp(20) : error C2664: 'fopen' : cannot convert parameter
1 from 'char' to 'const char *'
Any ideas?