Saturday, April 21, 2007

While I'm to tired to understand why this writes past the end of the array

#include <assert.h>
#define bounds(_i, _n)  (assert( (unsigned) (_i) < (_n) ), (_i) )
....

/*
 * fout is what we are appending to and should be open rw as necessary.
 * farray is an array of file pointers, "farsize" is the size of the array.
 */
void
concatenate( FILE *fout, FILE *farray[], const unsigned char *farsize) {

        int c;
        unsigned int fi = 1;
        FILE *fin;      /* current segment of farray[] to fout. */

        while ( (fi < farsize[0])) {
                fin = farray[bounds(fi, *farsize)];
                fi++;
                while ( (c = fgetc(fin )) != EOF ) {
                        fputc( c, fout );
                }
        }
}

I'm GOING TO BED. 0832 Zulu time on my clock.... must sleeep sleep....

what is that again?

1 comment:

  1. In retrospect, even zonked at that time of night, I do think that is the stupidest bit of code I have ever written in my entire life.

    ReplyDelete