lol
Anyway, ok, here is some of my code.
My encoder outputting the file size as 4 bytes:
Code:
/////////////get file size and send to decoder///////////////////
unsigned long count = 0;
INPUT_FILE.get();
while(!INPUT_FILE.eof())
{
count++; //use tellg instead?
INPUT_FILE.get();
}
INPUT_FILE.clear();
INPUT_FILE.seekg(0);
unsigned long temp = 255;
for(int i = 0; i < 4; i++)
{
unsigned long x = (count & temp);
x = x/int(pow(float(256), float(i)));
OUTPUT_FILE << char(x);
temp = temp * 256;
}
//count (32 bits long) is divided up into four bytes and sent out
yeah its kind of ugly but it works. My problem supposedly originates when my decoder tries to read these four bytes:
Code:
ifstream INPUT_FILE;
ofstream OUTPUT_FILE;
openFiles(INPUT_FILE, OUTPUT_FILE);
/////////////////////get file size/////////////////////
unsigned long count = 0;
unsigned long temp = 256;
for(int i = 0; i < 4; i++)
{
int t;
t = INPUT_FILE.get(); //doesn't work either if i use a char and get(char)
if(t < 0)
t+=256;
unsigned long x = t;
x = x*int(pow(float(temp), float(i)));
count += x;
}
In some cases this won't work. The encoder put my file size (26) into byte form, which is the substitution ascii character. ifstream refuses to read this character, but I've got to have a way to read all 256 ascii characters.
Thanks Sebastiani. I'll try it.