Here is the code written in c:
#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;
}
Here is the code written in c++:
#include <fstream>
#include<iostream>
#include <cstdio>
using namespace std;
int main()
{
int n;
string a;
cin>>n;
while(n--)
{
ifstream fin(__FILE__);
while(!fin.eof())
{
getline(fin,a,'\n');
cout<<a><<"\n";
}
}
return 0;
}
this is cool... thanks for the code! :)
ReplyDeleteAre you sure this is 'the quine'? I think you are just printing out the content of your code. Pardon my ignorance but I believe that ideal quine codes should not use files.
ReplyDeleteQuines are self printing codes.
ReplyDeleteThey do not read files.I have a doubt that this is a quine. And yeah plzz dont be offended