+int encode(CODE *table, char* inputfile, char *outputfile) {
+
+ FILE *fpsource,*fpdest;
+ int symbol,i;
+ char bit;
+ CODE symbolcode;
+
+ /* Abrimos el file */
+ if ((fpsource = fopen(inputfile,"rb")) == NULL) return 0;
+ if ((fpdest = fopen(outputfile,"wb")) == NULL) return 0;
+
+ while (!feof(fpsource)) {
+ /* Levanto un symbolo (byte) */
+ symbol = fgetc(fpsource);
+ if (symbol == EOF) continue;
+
+ /* Cargamos el codigo y lo emitimos */
+ symbolcode = table[symbol];
+ for (i = symbolcode.codelength; i > 0; --i) {
+ bit = (symbolcode.code >> (i-1)) & 1;
+ putbit(bit,0,0,fpdest);
+ }
+ }
+
+ /* Hacemos un flush de lo que haya quedado en el buffer de salida */
+ putbit(0,0,1,fpdest);
+ fclose(fpsource);
+ fclose(fpdest);
+ return 1;
+}
+