public
Created

Program that prints out its source code.

  • Download Gist
correct-self-rep.c
C
1 2 3 4 5 6 7 8 9
#include <stdio.h>
int main(int argc, char*argv[]) {
char s = '\\';
char p = '\"';
char n = '\n';
char *c[7] = {"#include <stdio.h>","int main(int argc, char*argv[]) {"," printf(","%s%c%s%c char s = '%c%c';%c char p = '%c%c';%c char n = '%cn';%c char *c[7] = {%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c};%c%s%c%s%c%s%c%s%c%s%c",",c[0],n,c[1],n,s,s,n,s,p,n,s,n,p,c[0],p,p,c[1],p,p,c[2],p,p,c[3],p,p,c[4],p,p,c[5],p,p,c[6],p,n,c[2],p,c[3],p,c[4],n,c[5],n,c[6],n);"," return 0;","}"};
printf("%s%c%s%c char s = '%c%c';%c char p = '%c%c';%c char n = '%cn';%c char *c[7] = {%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c};%c%s%c%s%c%s%c%s%c%s%c",c[0],n,c[1],n,s,s,n,s,p,n,s,n,p,c[0],p,p,c[1],p,p,c[2],p,p,c[3],p,p,c[4],p,p,c[5],p,p,c[6],p,n,c[2],p,c[3],p,c[4],n,c[5],n,c[6],n);
return 0;
}
$ gcc correct-self-rep.c
$ ./a.out > correct-self-rep.c
$ gcc correct-self-rep.c
$ ./a.out > correct-self-rep.c

I could do this all day!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.