Hi guys, first of all let me say that I'm a Delphi guys, but I've been cleaning up some old legacy C++ code without any real issues.
The following piece of code however baffles me!
It looks like it simply copies the binary input file to another file bit by bit, and does some funky bitwise stuff with int1 and int2, again for reasons unknown.
What also confuses me i.e. if I try write the output of the integers I get some funky results i.e.
fprintf(fTestFile, "%d\n", int2);
This gives me numbers in the 100s of thousands, which I would have thought out of the scope of a single char (this variable was originally a byte but MS VCpp would not compile the code.)
Anyone know what purpose it may all serve and why the bytes are going into the 1000s?
Major thanks in advance.
Joe.
bool ForLINUX, ForDOS;
char bWriteByte;
int iDataArray[1500];
int iCount, iOutFileH, int1, int2;
FILE *fInData, *fOutData, *fTestFile;
ForLINUX = false;
ForDOS = true;
fInData = fopen("\\Almeter\\baseline.dta", "rb");
fOutData = fopen("\\Almeter\\OutData.bin", "wb+");
iOutFileH = fileno(fOutData);
iCount = 0;
while(fread( &int1, 1,1, fInData) == 1) {
bWriteByte = int1;
if (ForLINUX) write(iOutFileH, &bWriteByte, 1);
if (ForDOS) _write(iOutFileH, &bWriteByte, 1);
int1 = (int1 << 8) & 0xff00;
if (!fread(&int2, 1,1, fInData)) exit(0);
int1 |= (int2 & 0xff);
iDataArray[iCount++] = int1;
bWriteByte = int2;
if (ForLINUX) write(iOutFileH, &bWriteByte, 1);
if (ForDOS) _write(iOutFileH, &bWriteByte, 1);
}
fclose(fInData);
fclose(fOutData);