i am having problems writing to a file. i am getting an access violation writing to the file. ive dug through the documentation for about an hour and i still cant figure out what im doing wrong.
here is my save code
Code:void CChildView::SaveMap( CString path ) { CFile file; const int SizeOfBuffer = mapSz.x * mapSz.y; int * buffer = new int [ SizeOfBuffer ]; int sizeBuffer[2]; try { file.Open( path, CFile::modeCreate ); sizeBuffer[0] = mapSz.x; sizeBuffer[1] = mapSz.y; for ( int i = 0; i < mapSz.y; ++i ) { for ( int j = 0; j < mapSz.x; ++j ) { buffer[i * mapSz.x + j] = map[i][j]; } } file.Write( sizeBuffer, 2 * sizeof(int)); file.Write( buffer, SizeOfBuffer * sizeof(int)); } catch (void) { MessageBox( "An error occured while writing to the file" ); } delete [] buffer; file.Close(); mapHasBeenEdited = FALSE; }