Writing a byte(which may not correspond to an ASCII character) to a file in C -
i writing compression program in c. uses run length , rice golomb encoding, applied @ bit leve. have written program , when print out 1's , 0's screen, correct. need able take file, compress , output file.
so have attempted store bits char, recieve them, , once have added 8 bits, print new file. not working me. nothing output file. think issue of bytes, not corresponding ascii character. suggestions please?
this code, recieve bit, add char , print char file once, 'filled'
void writebyte(char byte){ file *comp; comp = fopen("compfile.txt" "wb"); fprintf(comp,"%c", byte); putc(byte,comp); putchar(byte); printf("%c\n",byte); } void writebit(int bit){ if(ind >= 0){ byte|=(bit<<ind); ind-- } else{//if byte full writebyte(byte); //write byte file; reset(); writebit(bit); } }
when call fopen("compfile.txt", "wb");
existing file (if any) gets truncated 0 length. make work, need open file once @ beginning of program, , fclose
file @ end of program.
also, view file, need use hex editor.
Comments
Post a Comment