I'm trying to use fwrite to write an array of 65,536 8-bit values with a few other pieces of data added in. While I know how to use fwrite, the problem I'm having is with fopen - the pointer is always 0 when using wb mode. Basically:
The content in the if statement is being used as the file handle is 0. That I'd expect. However, shouldn't fopen, for writing, create the file if it doesn't exist or do I have to go into Windows Explorer and manually create the files and folders as needed (which shouldn't be necessary)?Code:int StartHeight; char SlopeData[65536]; ... // in a function GetCurrentDirectory(MAX_PATH, BasePath); // the location of the executable sprintf(FullPath, "%s\\data\\terrain\\Terrain03.dat", BasePath); // get the full path FileHandle = fopen(FullFileName, "wb"); // write output, binary mode if (FileHandle == 0) // if the file can't be found - report an error { sprintf(WarningString, "Error: file cannot be opened for writing", FullFileName); MessageBox(WindowHandle, WarningString, "File cannot be opened", MB_OK | MB_ICONHAND); } else // file found - write the needed data { fwrite(&StartHeight, 4, 1, FileHandle); // the baseline fwrite(SlopeData, 1, 65536, FileHandle); // the main data fclose(FileHandle); // close the file releasing the handle }



LinkBack URL
About LinkBacks



