A program that produces its source code as output

Can anyone think about a program in any programming language of your choice which will post its own source code as output?

Replies

  • Kaustubh Katdare
    Kaustubh Katdare
    No tries here? Where are our *crazy* computer engineers?
  • sauravgoswami
    sauravgoswami
    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...
  • sriramchandrk
    sriramchandrk
    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()
    {
    print "$_";
    }

    =========================

    Thanks & Regards
    Sriram
  • aashu_itdude
    aashu_itdude
    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
    #include
    #include
    #include
    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();
    }
  • emYth
    emYth
    Assuming that the source file names test.cpp

    #include
    #include
    using namespace std;
    
    int main()
    {
        freopen("test.cpp","rt",stdin);
        string g;
        while(getline(cin,g)&&cin)
        {
          cout<
                                        
  • Predictor
    Predictor
    sriramchandrk
    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
  • Manish Goyal
    Manish Goyal
    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);
    }
    }
    }
    
    
  • malardevi
    malardevi
    prakash.athani
    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.
  • trishna05
    trishna05
    #include
    char*s="#include %c char*s=%c%s%c;%c int main(void){printf(s,10,34,s,34,10,10);}";
    int main(void)
    {
    printf(s,10,34,s,34,10,10);
    }
  • Sahithi Pallavi
    Sahithi Pallavi
    😕 😲 😒

    PS : sorry for spamming.

You are reading an archived discussion.

Related Posts

freemarker is a template engine. i want to deliver a seminar on this topic, but it is too vast and the time for delivering seminar is just about 15 minutes....
Over the time, I've came across lot of engineers who say they'd rather work for a startup than MNC. What do you think? Why?
That was the topic of an interesting coffee-room discussion I participated in! 😁 Most of the software engineers confirmed that the dogs had a better life than them! IT engineers...
give me a best topic on electricals for my project😕
i am a EEE student.2nd year ......so wat are the topics on which i can do my projects......a working project ......