No tries here? Where are our *crazy* computer engineers?
This is a discussion on A program that produces its source code as output within the Computer Science & IT Engineering forums, part of the CE : Technical Discussions category; Can anyone think about it and post replies?...
Can anyone think about it and post replies?

No tries here? Where are our *crazy* computer engineers?
█ Founder & Administrator | CrazyEngineers® | admin{@}crazyengineers{dawt}com
█ About CE | Small Talk | Official Blog 'VoiCE' | Advertise On CE
█ The Big K's SuperBlogmt | Join CE! | Guide: How to post on CE







well its possible to write a programme to generate source codes,and it is possible here too,but the challenge is to generate codes according to the need of the hour,say less memory space,more sturdy,preference of tools so.on...
Be HaPpY !!!! U can GET me @ saurav@crazyengineers.com


There are 3 types of executable programs (interpreted(basic, perl) , compiled programs (c, pascal) & semi interpreted (java) )
You can produce its own source code as output only in interpreted programs.
its possible for semi interpreted using a process called as decompilation but the output may not be exactly same as initial source.
It not possible for compiled program.
example for interpreted program using perl.
=========================
#!/usr/bin/perl
open(INFILE, $0);
while(<INFILE>)
{
print "$_";
}
=========================
Thanks & Regards
Sriram

this c++ code reads the source file and displays the code as output. Its not a perfect code for this query but it can be further developed.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
void main()
{
clrscr();
int c=0;
char a[238];
ifstream fin("out.cpp"); //name of program
while(!fin.eof())
{
fin.read(a,238);
}
puts(a);
getch();
}
Last edited by aashu_itdude; 10th October 2008 at 08:17 PM.
AASHU IT DUDE
Assuming that the source file names test.cpp
Code:#include<iostream> #include<string> using namespace std; int main() { freopen("test.cpp","rt",stdin); string g; while(getline(cin,g)&&cin) { cout<<g<<endl; } return 0; }


...but there have been BASIC compilers and C interpreters. ???
-Will Dwinnell
Data Mining in MATLAB






Code:import java.io.*; class Source { public static void main(String args[])throws IOException { FileReader fr=new FileReader("Source.java"); int c; while((c=fr.read())!=-1) { System.out.print((char)c); } } }