Dave Cope's Homepage
   Main | Personal | Photo Gallery | Projects | Linux | Employment Info. | Links | Misc. | About e-mail  

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.

Source: quine.c


Warning: require_once(../../../../../../php/Beautifier/Init.php): Failed to open stream: No such file or directory in ../../functions.php on line 57

Fatal error: Uncaught Error: Failed opening required '../../../../../../php/Beautifier/Init.php' (include_path='.:/usr/pkg/lib/php82') in ../../functions.php:57 Stack trace: #0 ../../functions.php(312): InitBeatifier() #1 ../../functions.php(347): displayFile() #2 /sdf/www/af/d/dwcope/projects/quine/index.php(35): displayDLFile() #3 {main} thrown in ../../functions.php on line 57