/*	g.c
	generates the pointer table for max.1535 fortune cookies in
	file FORTUNES.TXT and writes it to file FORTUNES.TBL
	13 Apr 1988	A.Herrmann
*/

#include <stdio.h>

#define TMAX 1534

main()
{
	FILE	*inf, *outf;
	char	*infname = "B:FORTUNES.TXT";
	char	*outfname = "C:FORTUNES.TBL";
	long	fp,ptr[TMAX];
	unsigned i,count=0;

	inf = fopen(infname,"rb");
	ptr[count] = 0L;
	for (fp = 1L; !feof(inf); fp++) 
		if (getc(inf)==0) {
			ptr[++count] = fp;
/*			printf("%4d %ld\n",count,fp); */
		}
	fclose(inf);
	printf("%u cookies found\n");
	outf= fopen(outfname,"wb");
	if (count>TMAX) count=TMAX;
	putw(count,outf);
	putw(TMAX,outf);
	for (i=0; i<=count; i++)
		putl(ptr[i],outf);
	for (i=count+1; i<=TMAX; i++)
		putl(0L,outf);
	fclose(outf);
}
