Skip to content

Instantly share code, notes, and snippets.

@chaidhat
Created July 19, 2020 09:21
Show Gist options
  • Save chaidhat/9920e9ae052593e32dbb38ccd5367333 to your computer and use it in GitHub Desktop.
Save chaidhat/9920e9ae052593e32dbb38ccd5367333 to your computer and use it in GitHub Desktop.
self replicating code, inspired by https://cs.lmu.edu/~ray/notes/quineprograms/
#include <stdio.h>
int main () {
char *dat = "#include <stdio.h>%cint main () {%c%cchar *dat=%c%s%c;%c%cprintf(dat,10,10,9,34,dat,34,10,9,10);%c}";
printf(dat,10,10,9,34,dat,34,10,9,10);
}
@chaidhat
Copy link
Author

image

@chaidhat
Copy link
Author

information is stored in the char *dat which is then printed out with the printf() function. The information inside dat is exactly what is printed out. Use of %c is to substitute line breaks, tabs, quotation marks. Dat inserts itself into itself.
ASCII 9 - tab
ASCII 10 - line break
ASCII 34 - "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment