+ Reply to Thread
Results 1 to 9 of 9

A program that produces its source code as output

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?...

  1. #1
    CE - Regular Member prakash.athani's Avatar
    Join Date
    30th June 2008
    I'm a crazy: Computer Science & IT engineer

    Posts
    53

    Default A program that produces its source code as output

    Can anyone think about it and post replies?

  2. #2
    Good Administrator The_Big_K's Avatar
    Join Date
    26th November 2005
    I'm a crazy: Electrical engineer

    Location
    Terra-Firma
    Posts
    12,889

    Default Re: A program that produces its source code as output

    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

  3. #3
    CE - Ambassador sauravgoswami's Avatar
    Join Date
    26th February 2008
    I'm a crazy: Electronics engineer

    Location
    India
    Posts
    1,385

    Default Re: A program that produces its source code as output

    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

  4. #4
    CE - Regular Member
    Join Date
    25th September 2008
    I'm a crazy: CSE engineer

    Posts
    65

    Default Re: A program that produces its source code as output

    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

  5. #5
    CE - Apprentice aashu_itdude's Avatar
    Join Date
    25th June 2008
    I'm a crazy: Information Technology engineer

    Location
    gurgaon
    Posts
    14

    Default Re: A program that produces its source code as output

    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

  6. #6
    CE - Newbie
    Join Date
    13th October 2008
    I'm a crazy: Software engineer

    Location
    EGYPT
    Posts
    6

    Smile Re: A program that produces its source code as output

    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;
    }
    

  7. #7
    CE - Regular Member
    Join Date
    14th March 2009
    I'm a crazy: Computer engineer

    Location
    Pennsylvania, USA
    Posts
    74

    Default Re: A program that produces its source code as output

    Quote Originally Posted by sriramchandrk View Post
    There are 3 types of executable programs (interpreted(basic, perl) , compiled programs (c, pascal) & semi interpreted (java) )
    ...but there have been BASIC compilers and C interpreters. ???


    -Will Dwinnell
    Data Mining in MATLAB

  8. #8
    CE - Addict
    CEoM December 2009
    goyal420's Avatar
    Join Date
    20th September 2009
    I'm a crazy: Computer engineer

    Location
    punjab
    Posts
    1,520

    Default Re: A program that produces its source code as output

    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);
    }
    }
    }
    


    Most People don't know that they don't know what they want to do
    visit my blog:-http://goyal1989.blogspot.com/ Mail me :- goyal@crazyengineers.net

  9. #9
    CE - Newbie malardevi's Avatar
    Join Date
    24th February 2010
    I'm a crazy: Information Technology engineer

    Location
    Kovilpatti
    Posts
    1

    Thumbs up Re: A program that produces its source code as output

    Quote Originally Posted by prakash.athani View Post
    Can anyone think about it and post replies?
    I think try it by using the same file name in that program. open the same file read it and then print it. just try it.

+ Reply to Thread

Similar Threads

  1. Mouse programming in C
    By prabhat kumar in forum Computer Science & IT Engineering
    Replies: 9
    Last Post: 13th February 2010, 12:21 PM
  2. C Challenge: Self-Printing Program
    By The_Big_K in forum Computer Science & IT Engineering
    Replies: 32
    Last Post: 27th May 2009, 09:52 PM
  3. PC Tutorial: Parallel Port Interfacing Techniques - Part 2
    By xheavenlyx in forum Computer Science & IT Engineering
    Replies: 26
    Last Post: 11th January 2009, 02:01 AM
  4. Code Coverage Testing - Related to White box testing
    By Archana Kannouj in forum Computer Science & IT Engineering
    Replies: 7
    Last Post: 6th March 2008, 02:24 PM
  5. Problem: Output of this C Code
    By chaudharyssv in forum Computer Science & IT Engineering
    Replies: 6
    Last Post: 18th May 2007, 11:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts