I wrote a function to read back a binary file. When doing the debug, it showed "exception Thrown" on line "pFile=fopen(filename, "rb");". I don't know why. Also, how to return readback buffer in the function "read_back(const char*filename)"
void read_back(const char *filename)
{
FILE* pFile;
long lSize=100;
char* buffer;
buffer = (char*)malloc(sizeof(char)*lSize);
pFile = fopen(filename, "rb");
if (pFile == NULL) { fputs("File error", stderr); exit(1); }
// copy the file into the buffer:
size_t result = fread(buffer, 1, lSize, pFile);
if (result != lSize) { fputs("Reading error", stderr); exit(3); }
fclose(pFile);
}
int main()
{
const char *fname[2];
fname[1] = "C:\\1_data.bin";
fname[2] = "C:\\2_data.bin";
fname[3] = "C:\\3_data.bin";
for (int i = 0; i < 2; ++i)
{
read_back(fname[i]);
}
return 0;
}