program to print itself

This is a discussion on program to print itself within the C Programming forums, part of the General Programming Boards category; guys i have a small doubt..... Is it possible to write a program which when executed prints itself as the ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    73

    program to print itself

    guys i have a small doubt.....

    Is it possible to write a program which when executed prints itself as the output...
    i.e, the output should be the program itself.....

    the problem is using of files is not allowed.....

    i have no idea how to start without files....

    waiting for your ideas

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There was a post on the forum about 2 months back that did this. It was based on the program itself containing a copy of itself in hex in a char array - so you need to write a little preprocessor to take the file and generate a string of hex bytes, and then print those bytes twice in different ways.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,725
    Search the Web for "quine".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Nov 2007
    Posts
    73
    can you please direct me to that post....
    or give me the link or subject name if possible.......

    well it would be better if you can tell me the thing of preprocessor here.....

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm sure you are just as able as me to search the forum - and you are the one wanting to do it, so why should I perform the search.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Why don't you do as laserlight suggested? google.ca/search?q=quine
    How difficult is it to do a google search?

    You can find myriad examples here: http://www.nyx.net/~gthompso/self_c.txt
    Most of them aren't very legible.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    73
    thanxx got it!!!!!!!!!!!!!!!!!!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why is it that my program does not print for case 1?
    By Jasper in forum C Programming
    Replies: 10
    Last Post: 07-02-2009, 12:57 PM
  2. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 03:49 PM
  3. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 07:26 PM
  4. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21