Rare Witch Roundtable Podcast
Go Back   The Rare Witch Project Forums > Gaming > Rare & Playtonic > Homebrew Games and Tools

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.

Reply
 
Thread Tools
  #1  
Old 16th August 2009, 06:27 AM
mojobojo's Avatar
mojobojo mojobojo is offline
Dingpot
 
Join Date: Oct 2008
Location: Georgia
Total Awards: 1
INFECTED - B1K1 
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();
EDIT: I got some help from someone, turns out I needed to set the mode to Binary.

Last edited by mojobojo; 16th August 2009 at 11:49 AM.
Reply With Quote


  #2  
Old 16th August 2009, 06:11 PM
Airman's Avatar
Airman Airman is offline
The Hero of the Hour
 
Join Date: Jul 2006
Location: Don't
Total Awards: 2
You're Appreciated! INFECTED - B1K1 
Though I don't know the answer personally, I can forward it if you would still like help?
__________________
A.K.A Reborn
Reply With Quote


  #3  
Old 17th August 2009, 12:49 AM
mojobojo's Avatar
mojobojo mojobojo is offline
Dingpot
 
Join Date: Oct 2008
Location: Georgia
Total Awards: 1
INFECTED - B1K1 
Quote:
Originally Posted by Airman View Post
Though I don't know the answer personally, I can forward it if you would still like help?
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.
Reply With Quote


  #4  
Old 17th August 2009, 01:35 AM
cooliscool's Avatar
cooliscool cooliscool is offline
Dingpot
 
Join Date: Aug 2007
Location: SC, USA
Total Awards: 2
You're Appreciated! INFECTED - B1K1 
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.
Reply With Quote


  #5  
Old 17th August 2009, 05:46 AM
mojobojo's Avatar
mojobojo mojobojo is offline
Dingpot
 
Join Date: Oct 2008
Location: Georgia
Total Awards: 1
INFECTED - B1K1 
Quote:
Originally Posted by cooliscool View Post
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] = 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];
	}
Thanks for that, I'm gonna try and find some application to make to increase my programming skills. I guarantee I will need some help.
Reply With Quote


Reply


User Tag List

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 12:32 PM.


Forums powered by vBulletin® Copyright © Jelsoft Enterprises Ltd.
Website © 2000-∞ The RWP