self-reproducing C program

utzoo!decvax!harpo!floyd!cmcl2!mcbryan utzoo!decvax!harpo!floyd!cmcl2!mcbryan
Sun Nov 7 16:21:18 AEST 1982


_______________________________________________________________________________
#
/*
*			Self-Reproduction in C:
*
*	This is a complete self-reproducing C program.   To compile
*	and run, place text between the scored lines in a file, say junk.c,
*	and type:
*			cc junk.c -o junk
*			junk
*
*	Features:
*		1. Well-documented
*		2. Uses only fopen(), getc() and putc().
*		3. Looks very clean.
*
*	Oliver A. McBryan
*	New York University.
*/


#include <stdio.h>

main()
{
	FILE *file = fopen(__FILE__,"r");
	int c;

	while ((c=getc(file))!=EOF) putc(c,stdout);
}
______________________________________________________________________________



More information about the Comp.lang.c mailing list