473,245 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,245 software developers and data experts.

Output as SOURCE CODE itself !!

Dev
Hello Folks,

I need a "C" program, whose output display its SOURCE CODE
itself..

How can we do that? Please post solutions along with code
example (if possible)

Thanx..

Feb 9 '06 #1
13 2215
Dev said:
Hello Folks,

I need a "C" program, whose output display its SOURCE CODE
itself..

How can we do that? Please post solutions along with code
example (if possible)


/* save this file as foo.c */
#include <stdio.h>

int main(void)
{
FILE *fp = fopen("foo.c", "r");
if(fp != NULL)
{
int ch;
while((ch = getc(fp)) != EOF)
{
putchar(ch);
}
fclose(fp);
}
return 0;
}

Alternatively, look up "quine" on the Web.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Feb 9 '06 #2

Richard Heathfield wrote:
Dev said:
Hello Folks,

I need a "C" program, whose output display its SOURCE CODE
itself..

How can we do that? Please post solutions along with code
example (if possible)
/* save this file as foo.c */
#include <stdio.h>

int main(void)
{
FILE *fp = fopen("foo.c", "r");

---------------------------------------------------------------------------------
replace the above line with
FILE *fp = fopen(__FILE__,"r");
--------------------------------------------------------------------------------- if(fp != NULL)
{
int ch;
while((ch = getc(fp)) != EOF)
{
putchar(ch);
}
fclose(fp);
}
return 0;
}

Alternatively, look up "quine" on the Web.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


Feb 9 '06 #3
Dev
Thanks Richard, that's what i thought, with file handlings we can do
this..

Feb 9 '06 #4
"Dev" <kr**********@gmail.com> writes:
Thanks Richard, that's what i thought, with file handlings we can do
this..


One more time, please read <http://cfaj.freeshell.org/google/>
*before* you post here again. Thanks.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 9 '06 #5
Dev

Keith Thompson wrote:
"Dev" <kr**********@gmail.com> writes:
Thanks Richard, that's what i thought, with file handlings we can do
this..
One more time, please read <http://cfaj.freeshell.org/google/>
*before* you post here again. Thanks.


Hello Keith,
Thank for giving me link, i will follow the "Reply" format, sorry for
previous post, thanks once again..
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


Feb 9 '06 #6
Sunil Varma said:

Richard Heathfield wrote:

/* save this file as foo.c */
#include <stdio.h>

int main(void)
{
FILE *fp = fopen("foo.c", "r");

--------------------------------------------------------------------------------- replace the above line with
FILE *fp = fopen(__FILE__,"r");


Each has advantages and disadvantages.

__FILE__ will typically be replaced by a full path spec for the file, which
means you can run the program from anywhere on that system and still have
it pick up the file from that path - but if you move the program to a
different but compatible system, you must then reconstruct that path on the
new system and place the source file there, whereas my way you need only
dump the source file in any old place and then run the program from that
directory. (Yes, all these references to paths and directories make this
moderately off-topic.)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Feb 9 '06 #7
Dev said:
Thanks Richard, that's what i thought, with file handlings we can do
this..


Now that you've learned that, go look up "quine" on the Web.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Feb 9 '06 #8
Dev

Richard Heathfield wrote:
Dev said:
Thanks Richard, that's what i thought, with file handlings we can do
this..
Now that you've learned that, go look up "quine" on the Web.

Sorry, Richar, could u tell me what do u mean by "quine"
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


Feb 9 '06 #9
Dev said:

Richard Heathfield wrote:
Dev said:
> Thanks Richard, that's what i thought, with file handlings we can do
> this..


Now that you've learned that, go look up "quine" on the Web.

Sorry, Richar, could u tell me what do u mean by "quine"


It's something you look up on the Web. Consider the possibilities inherent
in a Web search engine such as Google or Altavista. Consider also the fact
that I would not have suggested that you look up the word "quine" if it
were not relevant to your question.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Feb 9 '06 #10
Richard Heathfield <in*****@invalid.invalid> writes:
Dev said:

Richard Heathfield wrote:
Dev said:

> Thanks Richard, that's what i thought, with file handlings we can do
> this..

Now that you've learned that, go look up "quine" on the Web.

Sorry, Richar, could u tell me what do u mean by "quine"


It's something you look up on the Web. Consider the possibilities inherent
in a Web search engine such as Google or Altavista. Consider also the fact
that I would not have suggested that you look up the word "quine" if it
were not relevant to your question.


He may be confused by the fact that the top site listed appears to be
for gay, black, disabled, Scottish women... :)

--

John Devereux
Feb 9 '06 #11
John Devereux:
Richard Heathfield:

that I would not have suggested that you look up the word "quine" if it
were not relevant to your question.


He may be confused by the fact that the top site listed appears to be
for gay, black, disabled, Scottish women... :)


Adding "source" to the search helps a lot.

Jirka
Feb 9 '06 #12
"Dev" <kr**********@gmail.com> writes:
Keith Thompson wrote:
"Dev" <kr**********@gmail.com> writes:
> Thanks Richard, that's what i thought, with file handlings we can do
> this..


One more time, please read <http://cfaj.freeshell.org/google/>
*before* you post here again. Thanks.


Hello Keith,
Thank for giving me link, i will follow the "Reply" format, sorry for
previous post, thanks once again..

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


Excellent, thank you.

One more thing: it's rarely necessary to quote the *entire* article to
which you're replying. You should delete anything that's not relevant
to your followup, while making sure that the attribution lines for
anythink you *do* quote are still there. Don't quote signatures
unless you're actually commenting on them.

Most posters here get this mostly right, so following their example is
a good approach.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 9 '06 #13
On Thu, 09 Feb 2006 12:42:02 +0000, in comp.lang.c , John Devereux
<jd******@THISdevereux.me.uk> wrote:
Richard Heathfield <in*****@invalid.invalid> writes:
Dev said:

Sorry, Richar, could u tell me what do u mean by "quine"


It's something you look up on the Web.


He may be confused by the fact that the top site listed appears to be
for gay, black, disabled, Scottish women... :)


Sure, but the /third/ entry looks kinda relevant (smiley noted...)
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Feb 9 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Neil Zanella | last post by:
OK, this time the compiler's got me a little bit puzzled, simply because it is doing something I am not expecting. My understanding, according to the documentation of std::vector<>::resize(), is...
6
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to...
2
by: alice | last post by:
Hi, When I compiles the following program with g++, it gives the following output: # g++ -o list list.C list.C: In function `int main()': list.C:116: jump to case label list.C:110: crosses...
13
by: Peter Ammon | last post by:
I invented a new (AFAIK) way of doing the O part of C's I/O that is safer than printf() without sacrificing much convenience. It looks a bit like C++'s formatted output, without the stupid gotchas...
16
by: Puneet | last post by:
Hi ALL, I have a silly question... (may be) Can we write a single line C program whose output is the program itself? Is anybody know the answer please tell me. Puneet
2
by: Slipperman | last post by:
i'm sure everyone has used the View Source option off the rmb menu to look at the source of a page. question: is there a way to output the source of a page to a file at run time via a button or...
16
by: msundaram.visvanathan | last post by:
Hi, i tried to write this small code in C which would: Input :a b c d Output:abcd code: #include<stdio.h>
7
by: Steve Hershoff | last post by:
Thanks to this newsgroup I've been pointed to Microsoft's XML Diff & Patch utilities. I've been reading about how I can use the tools to generate a diffgram between two XML documents, and how the...
15
by: vinay.khankari | last post by:
How to Print the complete source program as output of the program?
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.