我遇到了一个程序,它打印在this网站上,即它打印程序代码。打印自己的程序,它是如何工作的?
程序代码是:
#include <stdio.h>
char *program = "#include <stdio.h>%cchar *program = %c%s%c;%cint main()%c{%cprintf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);%c return 0;%c}%c";
//what is this line doing, what is the use of %c and %s and what properties of %c and %s are being used here?
int main()
{
printf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);
//what is this print function doing, and how?
return 0;
}
而且给出的解释是:
两个关键技巧在这里使用了嵌入式%S 说明符的字符串,使字符串包含本身打印时,并使用%c格式说明符 允许打印出像换行符那样的特殊字符 ,否则该字符串不能嵌入输出 字符串中。
我不明白该程序是如何工作的。我已经提到了我需要的解释,他们是如何工作的以及他们在做什么。请解释。
我已经看到了这个问的次数最近。这是一个家庭作业或程序员的挑战吗? –
没有这样的事,我只是碰到它。如果这是一个家庭作业,我会使用作业标签。 – SpeedBirdNine
你的评论打破了奎因:)另外,缩进在奎因中是不正确的。 [这是我最近在C++中的quine](http://codepad.org/sKvDs2Et)@MichaelDorgan:是的,它是一个历史根源的程序员的挑战 – sehe