Quite Smart RIddle

S

snaidis

I'm new here and I have a quite smart riddle for you people:
Try to write a program which prints itself.
I have a pretty interesting article about this programming problem with
the answer, but first of all try to solve it by yourself.

Have a good day.
 
D

deepak

I know the article 'll be Ken Thompson's classical code.
I tried to do it.
But never came anywhere near to his idea.
Still i don't know how he is printing it using the string.
If anyone know can you please explain it to me?

Deepak.
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm new here and I have a quite smart riddle for you people:
Try to write a program which prints itself.
I have a pretty interesting article about this programming problem with
the answer, but first of all try to solve it by yourself.

Most of us have written C quines at least once.
I suggest that you google for 'quine'. There are quite a few C solutions
available.
Have a good day.

You too.

- --

Lew Pitcher, IT Specialist, Corporate Technology Solutions,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEiZaLagVFX4UWr64RAgFeAJ48wUfdiEhyw63aHl/1CXh1XuU2ZgCg8d3+
nFjXk3M9/ny90RSI4ThT65k=
=KZZr
-----END PGP SIGNATURE-----
 
N

Nelu

I'm new here and I have a quite smart riddle for you people:
Try to write a program which prints itself.
I have a pretty interesting article about this programming problem with
the answer, but first of all try to solve it by yourself.

A Quine?
What'd you say if I showed you a quine in C that was also a palindrome?
(That's if I can still find it, although you can probably google for it).
Look on wikipedia for Quine. There you can find information about them
if you are interested.

If you are talking about a quine then you have to know that the program
prints its source code and not itself.
 
P

parcour

I'm new here and I have a quite smart riddle for you people:
Try to write a program which prints itself.
I have a pretty interesting article about this programming problem with
the answer, but first of all try to solve it by yourself.

Ok:

/*This is my ugly C quine.*/
#include <stdio.h>
char *quine="void quotate(char
*s){while(*s){if(*s=='\\\\'||*s=='\\\"')putchar('\\\\');putchar(*s);s++;}}int
main(){printf(\"/*This is my ugly C quine.*/\\n#include
<stdio.h>\\nchar
*quine=\\\"\");quotate(quine);printf(\"\\\";\\n%s\",quine);}";
void quotate(char
*s){while(*s){if(*s=='\\'||*s=='\"')putchar('\\');putchar(*s);s++;}}int
main(){printf("/*This is my ugly C quine.*/\n#include <stdio.h>\nchar
*quine=\"");quotate(quine);printf("\";\n%s",quine);}

Not very compact or clever, but it works (before Google Groups messes
with the line breaks, anyway).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,969
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top