c program

P

Pravin Shetty

Hi
I would like to know how to print the program itself as the output of
that same program without using files...

eg:
#include<stdio.h>
void main()
{
printf("hello");
-
-
-
-
}

This is the program. On execution of this program,the output should be

#include<stdio.h>
void main()
{
printf("hello");
-
-
-
-
}

thank you
Reagrds
Pravin
 
S

Serge Paccalin

Le mardi 18 janvier 2005 à 10:54, Pravin Shetty a écrit dans
comp.lang.c :
Hi
I would like to know how to print the program itself as the output of
that same program without using files...

Look for "quine" on the web.

http://www.nyx.net/~gthompso/self_c.txt

--
___________ 2005-01-18 12:18:47
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Il faut donc que les hommes commencent
-'(__) par n'être pas fanatiques pour mériter
_/___(_) la tolérance. -- Voltaire, 1763
 
J

Jonathan Burd

Pravin Shetty wrote:
[...]
#include<stdio.h>
void main()
Umm, Stop quining! Learn to not void main() first. This is what the C
standard has to say about this:

<quote>

5.1.2.2.1 Program startup

[#1] The function called at program startup is named main.
The implementation declares no prototype for this function.
It shall be defined with a return type of int and with no
parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv,
though any names may be used, as they are local to the
function in which they are declared):

int main(int argc, char *argv[]) { /* ... */ }

or equivalent;8) or in some other implementation-defined
manner.

{
printf("hello");
[...]
Missing something important? `return 0;`
[...]


Regards,
Jonathan.

--
C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
C Library: http://www.dinkumware.com/refxc.html
C99 Standard Draft: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/

"If unsigned integers look like two's complement (signed) integers,
it's because two's complement integers look like unsigned integers."
-Peter Nilsson
 
D

Debian User

A simple example, ugly, but it works :)
char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}";main(){printf(s,34,s,34);}
 
J

Jonathan Burd

Debian said:
A simple example, ugly, but it works :)
char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}";main(){printf(s,34,s,34);}
[...]

Please do not toppost in c.l.c. The regulars here seem to dislike it.
Secondly, topposting blurs the context.

--
C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
C Library: http://www.dinkumware.com/refxc.html
C99 Standard Draft: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/

"I'm learning to program, because then,
I can write programs to do my homework faster." - Andy Anfilofieff
 
D

Debian User

Jonathan Burd said:
Debian said:
A simple example, ugly, but it works :)
char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}";main(){printf(s,34,s,34);}
[...]

Please do not toppost in c.l.c. The regulars here seem to dislike it.
Secondly, topposting blurs the context.
sorry, I was used to post in BBS :(
I am new here and not very clear with something
 

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

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top