c - 如何反转蒯因?

标签 c quine

我写了一个 C 程序,它自己打印 n 次,但我不知道如何反向打印同样的 n 次。例如,如果示例程序是:

hello

那么要求的输出应该是 "olleh"for n=1。 这是我的 quine 程序,

#include <stdio.h>
int main()
{
  int n;
  char c;
  FILE *f;
  f=fopen(__FILE__,"r");
  scanf("%d",&n);
 while(n--)
 {
 while((c=getc(f))!=EOF)
 putchar(c);
 fseek(f,0,0);
 }
  return 0;
} 

最佳答案

这不是纯奎因。参见 the Quine article in Wikipedia :

A quine takes no input. Allowing input would permit the source code to be fed to the program via the keyboard, opening the source file of the program, and similar mechanisms.

关于c - 如何反转蒯因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3693924/

相关文章:

c - 打印自己的程序,它是如何工作的?

c - g_signal 延迟(C、GTK+)

c - 释放 C 中的文件写锁?

c - 诊断进程卡在D状态(不可中断 sleep /阻塞IO)

language-agnostic - 复杂的多队列是如何编写的?

c - 这个程序如何 self 复制?

c - 打印数组时的额外值(从 %s 转换为 %c)

c - 从 C 数组中删除重复的数字

lisp - Common-LISP Print 函数本身

ruby - 了解 ruby 奎因