输出为SOURCE CODE本身!! [英] Output as SOURCE CODE itself !!
问题描述
Hello Folks,
我需要一个C程序,其输出显示其源代码
本身..
我们怎么能这样做?请发布解决方案以及代码
示例(如果可能)
Thanx ..
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..
推荐答案
Dev说:
Dev said:
Hello Folks,
我需要一个C程序,其输出显示其源代码本身..
我们怎么能这样做?请发布解决方案和代码
示例(如果可能)
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)
/ *将此文件另存为foo.c * /
#include< stdio.h>
int main(无效)
{
FILE * fp = fopen(" foo.c"," r");
if(fp!= NULL)
{
int ch;
while((ch = getc(fp))!= EOF)
{
putchar(ch);
}
fclose(fp);
}
返回0;
}
或者,查看quine在网上。
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然放弃了www)
/* 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)
Richard Heathfield写道:
Richard Heathfield wrote:
Dev说:
Dev said:
Hello Folks,
我需要一个C程序,其输出显示其源代码本身..
我们怎么能这样做?请将解决方案与代码一起发布
示例(如果可能)
/ *将此文件另存为foo.c * /
#include< stdio.h>
int main(void)
{FILE * fp = fopen(" foo.c"," r");
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");
----- -------------------------------------------------- --------------------------
用
FILE * fp替换上面一行= fopen(__ FILE __," r");
------------------------------- -------------------------------------------------- if(fp!= NULL)
{
int ch;
while((ch = getc(fp))!= EOF)
{
putchar(ch) ;
}
fclose(fp);
}
返回0;
}
或者,查看quine在网上。
-
理查德希思菲尔德
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上面的域名(但显然放弃了www)
---------------------------------------------------------------------------------
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)
谢谢Richard,'这就是我的想法,我们可以做文件处理
这个..
Thanks Richard, that''s what i thought, with file handlings we can do
this..
这篇关于输出为SOURCE CODE本身!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!