Quine Tutorial
Introduction
Creating a program whose output is the program itself isn't (at least
initially) a trivial task. However, it is actually quite simple once you
figure it out. In fact, it took me about 15min to create the final program. I
decided to create a tutorial on how to generate such a program.
The Quine Page has many
quines for various languages. The page includes an extremely short program
written in C that reproduces itself. Instead of trying to break some sort of
record, my intent is to create a quine whose creation can be easily
understood.
Note:To keep things more readable, I ran "indent" on the source code
to make it more readable on line. To get the unmodified source code and
Makefile, please download quine.tar.gz. You will
need to make a couple small changes to the make file depending on what platform
and compiler you are using.
End Result
First of all, I am going to show you the "final" program. This is the end
result of the tutorial. However, generating this program by hand would be
extremely difficult, and it is really hard to change if you make a mistake.
|