|
Homebrew Games and Tools If you've created a trainer, texture editor, or a full-blown fangame we'd like to see it here. Show off your mad programming skills. |
|
Thread Tools |
#1
|
||||
|
||||
File Reading/Writing problems c++
So im using this code. Works until I get to 0x109 then all of the bytes in the file are 0xCD. I have no clue how to fix this.
Code:
fstream FileOpen("C:\\Binary.bin"); FileOpen.seekg(0, ios::end); int FileSize = FileOpen.tellg(); FileOpen.seekg(0, ios::beg); char* FileBuffer = new char[FileSize]; FileOpen.read(FileBuffer, FileSize); char* GBuffer = new char[FileSize]; for (int i = 0; i < FileSize; i++) { GBuffer[i] = FileBuffer[i]; } fstream NewFile("C:\\NewFile.bin", ios::out); NewFile.write(GBuffer, FileSize); NewFile.flush(); NewFile.close(); Last edited by mojobojo; 16th August 2009 at 11:49 AM. |
#2
|
||||
|
||||
Though I don't know the answer personally, I can forward it if you would still like help?
__________________
A.K.A Reborn |
#3
|
||||
|
||||
Nah I have gotten some help and it works fine now. But I'm doing most of my code in C++ now for learning purposes so I will most likely be back with need of some help.
Last edited by mojobojo; 17th August 2009 at 05:43 AM. |
#4
|
||||
|
||||
Optimized your array copy code a little. Should save some clock cycles by copying in 16 byte intervals rather than the loop having to increment i by one.
Code:
for (int i = 0; i < FileSize - 16; i+=16) { GBuffer[i] = FileBuffer[i]; GBuffer[i+1] = FileBuffer[i+1]; GBuffer[i+2] = FileBuffer[i+2]; GBuffer[i+3] = FileBuffer[i+3]; GBuffer[i+4] = FileBuffer[i+4]; GBuffer[i+5] = FileBuffer[i+5]; GBuffer[i+6] = FileBuffer[i+6]; GBuffer[i+7] = FileBuffer[i+7]; GBuffer[i+8] = FileBuffer[i+8]; GBuffer[i+9] = FileBuffer[i+9]; GBuffer[i+10] = FileBuffer[i+10]; GBuffer[i+11] = FileBuffer[i+11]; GBuffer[i+12] = FileBuffer[i+12]; GBuffer[i+13] = FileBuffer[i+13]; GBuffer[i+14] = FileBuffer[i+14]; GBuffer[i+15] = FileBuffer[i+15]; } Last edited by cooliscool; 17th August 2009 at 05:48 AM. |
#5
|
||||
|
||||
Quote:
|
Thread Tools | |
|
|