Hi I have this program set to read a binary file and output each bit as 2 bytes of data to another file.
The conversion is fine, however the program just doesn't read the entire input file it stops in the middle.
Code:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
FILE* fpread;
FILE* fpwrite;
char c;
int buffer;
int buffer2=0;//starts with low impulse
int a;
int main (void)
{
//Open Data File
fpread = fopen("dta.tsc", "rb");
fpwrite = fopen("dta_READY.bin", "wb");
//Read File and Convert each Bit to 2 Bytes
c = getc(fpread);
while ( c !=EOF )
{
for(a = 7; a >= 0; a--)
{
putc (buffer2,fpwrite);
buffer = (int)c;
buffer = buffer>>a;
buffer = buffer &1;
if (buffer==1)
{
buffer = buffer2 ^ 1;
putc(buffer,fpwrite);
}
else
{
buffer = buffer2;
putc(buffer2,fpwrite);
}
buffer2 = buffer ^ 1;//buffer2 equals buffer XOR 1
}
c = getc(fpread);
}
fclose(fpread);
fclose(fpwrite);
return 0;
}
I am just trying to understand why it doesn't read my entire input file... any ideas? I would think the while(c!=EOF) would have done the job what am I missing????