C++ - Opening a file inside a function using fopen
- by Josh
I am using Visual Studio 2005 (C++).
I am passing a string into a function as a char array. I want to open the file passed in as a parameter and use it. I know my code works to an extent, because if I hardcode the filename as the first parameter it works perfectly.
I do notice if I look at the value as a watch, the value includes the address aside the string literal. I have tried passing in the filename as a pointer, but it then complains about type conversion with __w64. As I said before it works fine with "filename.txt" in place of fileName. I am stumped.
void read(char fileName[50],int destArray[MAX_R][MAX_C],int demSize[2])
{
int rows=0;
int cols=0;
int row=0;
int col=0;
FILE * f = fopen(fileName,"r");
...