Advertisement

Having Problem with allocation

Started by January 04, 2003 01:24 PM
0 comments, last by Metal Typhoon 21 years, 10 months ago
just for you have an idead i have this function and i have a message box to output a value to check to see if it was created but when i check the valeu within the function it works.. outside of it it doesn't .. it looks like it didn't do anything to the data .. "it's did use the &" ..
  
unsigned char **Data;

void LoadRaw (char *filename,int Size,unsigned char **Data)
{
	ifstream File (filename,ios::binary);

	Data = new unsigned char *[Size];
	for (int i = 0; i < Size; i++)
		Data[i] = new unsigned char [Size];

	for (int X = 0; X < Size; X++);
		for (int Y = 0; Y < Size; Y++)
			File.read (reinterpret_cast <char *> (Data[Y]),Size);

	
	char Buffer[10];
	sprintf (Buffer,"%d",Data[10][10]);
	MessageBox (NULL,Buffer,"",MB_OK);

	
	File.close();

};
  
what am i doing wrong ? [edited by - Metal Typhoon on January 4, 2003 3:21:26 PM]
Metal Typhoon
this is the way i wrote fstreams a couple years ago hope this helps

//filework
#include *******************************
#include

class fbinappio
{
private:
int lastobjsaved;
int lastobjmade;
int i;
int obj[10];
fstream FILEHNDLE;
public:
fbinappio(){}
void openfile()
{
FILEHNDLE.open("object.dat",ios::app|ios::in|ios::out|ios::binary);
if(!FILEHNDLE)
{cout<<"COULND NOT OPEN FILE";exit(1);}

}
// fileload(int sizeofobject,&objptr);
// filesave(int lastobjmade,int lastobjsaved,int sizeofobj,void **objptr);
// }
//};
void filesave(int lastobjmade,int lastobjsaved,int sizeofobj,void **objptr)
{
openfile();
for(i=lastobjsaved;i<=lastobjmade;++i)
{
FILEHNDLE.write((char*)objptr,sizeofobj);
}
FILEHNDLE.close();
}

void fileload(int sizeofobject,void **objptr)
{ int i;
openfile();
FILEHNDLE.seekg(0, ios::end); // goto end
int endposition = FILEHNDLE.tellg(); // find where we are
int numofobjs = endposition / sizeofobject; // number of objects
for(i=0;i {
int position = i * sizeofobject; // number times size
FILEHNDLE.seekg(position); // bytes from begin
FILEHNDLE.read((char*)*objptr, sizeofobject);
}
FILEHNDLE.close();
}
};




This topic is closed to new replies.

Advertisement