GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 84 of 203    Print  
How do you write a program which produces its own source code as its output?

  
Total Answers and Comments: 4 Last Update: January 07, 2007     Asked by: arup 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Ashish
 
include<iostream>
#include<fstream>
using namespace std;
int main()
{
             fstream *obj = new fstream();
             obj->open ("main.cpp"); // file path
              cout<<obj->rdbuf();
              return 0;

}

Above answer was rated as good by the following members:
j_l_larson
June 07, 2006 06:41:06   #1  
bappa        

RE: How do you write a program which produces its own ...

write this program and save it as pro.c....run....it will show the program to the consol and write the source code into data.txt file...................

#include<stdio.h>
void main()
{
FILE *fp *ft;
char buff[100];
fp fopen( pro.c r );
if(fp NULL)
{
printf( ERROR );
}
ft fopen( data.txt w+ );
if(ft NULL)
{
printf( ERROR );
}
while(getc(fp)! EOF)
{

fscanf(fp s buff);
printf( s\n buff);
fprintf(ft s\n buff);
}
}


 
Is this answer useful? Yes | No
June 29, 2006 10:43:10   #2  
Biju Nair        

RE: How do you write a program which produces its own ...

A program that produces its complete source code as its only output is called a quine.

Eg:

char*f char*f c s c;main()
printf(f 34 f 34 10); c ;
main()printf(f 34 f 34 10);


 
Is this answer useful? Yes | No
July 26, 2006 13:11:04   #3  
Jayashree        

RE: How do you write a program which produces its own ...
#include stdafx.h #include string.h #include process.h int main(int argc char* argv[]){ char cmd[125]; strcpy(cmd type ); strcat(cmd __FILE__); system(cmd); return 0;}
 
Is this answer useful? Yes | No
January 07, 2007 08:02:18   #4  
Ashish        

RE: How do you write a program which produces its own ...
include<iostream>
#include<fstream>
using namespace std;
int main()
{
fstream *obj new fstream();
obj->open ( main.cpp ); // file path
cout<<obj->rdbuf();
return 0;

}

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape