Closed Thread Icon

Preserved Topic: code that shows itself... (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=16624" title="Pages that link to Preserved Topic: code that shows itself... (Page 1 of 1)" rel="nofollow" >Preserved Topic: code that shows itself... <span class="small">(Page 1 of 1)</span>\

 
lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 06-19-2002 08:57

I remember seeing a code snippet that when ran it shows its own source code.
and when viewed with a fileviewer you see the same source code as when ran!

so consider this:

./myapp > out.txt
./cat myapp.c > src.txt

now run a compare on both out.txt and src.txt and you will notice that there are the same!

how can that be done!?

i forgot how...it was a bit tricky!

//lallous

[edit: typos]

[This message has been edited by lallous (edited 06-21-2002).]

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 06-19-2002 10:51

yes, that is indeed very tricky!
i did that once as a unix shell script, let me see if i can find it.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 06-19-2002 11:23

here is a Jscript version:

code:
function rep(text) {WScript.Echo(text + '(' + String.fromCharCode(34) + text + String.fromCharCode(34) + ');');} 
rep("function rep(text) {WScript.Echo(text + '(' + String.fromCharCode(34) + text + String.fromCharCode(34) + ');');} rep");


execute it with cscript rep.js from your command prompt.

and i also found a gcc version:

code:
main(a){printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34;}



and a general c version:

code:
#include<stdio.h> 
#define S(P) main(){printf("#include<stdio.h>\n#define S(P) %s\nS(%s)",#P,#P);}
S(main(){printf("#include<stdio.h>\n#define S(P) %s\nS(%s)",#P,#P);})



have fun!

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 06-19-2002 14:07

Grumble, Thanks alot!

abb
Bipolar (III) Inmate

From: Victoria, BC
Insane since: Mar 2002

posted posted 06-20-2002 19:57

but those scripts only print the code that you tell it, if the code REALLY printed itself, there would be an infinite number of printf("#include.....printf("#include.......printf(..printf(.printf..printf(...........
so that code *technically* doesn't print it's source code, it's source code IS DIFFERENT than what it prints.
wouln't it? or am i not understanding again?


Padded Room #623

abb
Bipolar (III) Inmate

From: Victoria, BC
Insane since: Mar 2002

posted posted 06-20-2002 20:08

... the C code doesn't work on my Win98 machine ...
http://www.islandnet.com/~bradford/abb/loopsrc.bmp \
http://www.islandnet.com/~bradford/abb/loopcomp.bmp

abb
Bipolar (III) Inmate

From: Victoria, BC
Insane since: Mar 2002

posted posted 06-20-2002 20:15

oh.............................................., i'll shut up now...


Padded Room #623

massacre
Bipolar (III) Inmate

From: the space between us
Insane since: Dec 2001

posted posted 06-20-2002 22:16

G-MAN, thatz cool and important

maybe we should add it to the archives?

CELL 557

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-23-2002 16:16

just thought I would mention it, this kind of program is called a 'quine'.

They're more complex than 'hello world', but not really that complex in most languages... I even saw one in english once.

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 06-24-2002 06:19

tp, nice to know it's called 'quine' ...
i'm curious to see the other more complex codes!! have any urls?



Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 06-24-2002 17:22

http://c2.com/cgi/wiki?QuinePrograms
for some more.

« BackwardsOnwards »

Show Forum Drop Down Menu