Revision: 18882
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 11, 2009 10:37 by Zydeco
Initial Code
int rle_encode_file (FILE * in, FILE * out) { int block_len, block_char, c; block_len = 0; block_char = -1; for(;;) { c = getc(in); if (c == EOF) break; if (c == block_char && block_len < 255) { /* same block */ block_len++; } else { if (block_len) { /* write block */ putc(block_len, out); putc(block_char, out); } /* start new block */ block_len = 1; block_char = c; } } if (block_len) { /* last block */ putc(block_len, out); putc(block_char, out); } return 1; } int rle_decode_file (FILE * in, FILE * out) { int i, len, c; for(;;) { len = getc(in); /* block length */ c = getc(in); /* character */ /* checking */ if (len == EOF) return 1; /* end of file */ if (c == EOF) return 0; /* bad format */ /* output */ for(i = 0; i < len; i++) putc(c, out); } }
Initial URL
http://en.wikipedia.org/wiki/Run-length_encoding
Initial Description
Encode and decode RLE from files
Initial Title
RLE Encoding and decoding
Initial Tags
Initial Language
C