Mail Archives: djgpp/2000/03/29/14:35:28
Nate Eldredge wrote:
>
> I suspect what you'd do is to have a buffer of at least one byte, then
> return bits from this buffer, and refill it when empty. Something
> like:
>
> int buf; /* we really only use one byte of it */
> int bits_left = 0;
>
> /* Note this reads the least significant bit first... it could be
> changed. */
> int get_bit() {
> int bit;
> if (bits_left == 0) {
> buf = getc(input); /* read one byte */
> /* handle error or EOF case */
> }
> bit = buf & 1; /* get least significant bit */
> buf >>= 1; /* shift for the next time */
> bits_left--; /* and note that we've used one bit */
> return bit;
> }
>
> Presumably the code you have does the same thing, but associates a
> buffer with each file (which is why there are the funny structs).
> This allows you to get bits from multiple files at once.
Yes,this is the actual code...(its found in "bitfiles.c"
from the snippits code collection that can be downloaded from:
http://www.snippets.org/ )
int bfread(bfile *bf)
{
if (0 == bf->rcnt) /* read new byte */
{
bf->rbuf = (char)fgetc(bf->file);
bf->rcnt = 8;
}
bf->rcnt--;
return (bf->rbuf & (1 << bf->rcnt)) != 0;
}
I just dont understand how the end of file was implemented
yet.....
The header file #includes other headers and those #include other
headers...I just want to chop everything up and put it in one
file that i can #include in my sources.....
I am finding this difficult,cause i dont understand all the
caveats of headers and #include'd files....Anyhelp on doing
this would be SUPER cool.
--
|"""""<`.THE PRINCE ,'>"""""""""""""""""""""""""""""""""""|
| `.`/""""""\,',' my sig is too big, |
|SEE HIS ( / \ \' SEE HIS but its really cool. |
| FACE \/<> <>\/ SMILE |
| / W \ Visit my ascii art site: |
| ,'\_|||||_/`. http://www.gtcom.net/~krogg/ascii/ |
| ,',' ||| `.`. krogg DOT no DOT to DOT spam AT gtcom DOT net |
|____<,' TIME TO DIE `.>____Remove no.to.spam to reply____|
- Raw text -