C++ program to print itself

This is a discussion on C++ program to print itself within the C++ Programming forums, part of the General Programming Boards category; I wanna write a C++ program that can print out the source code of the program, but this program can't ...

  1. #1
    Unregistered
    Guest

    C++ program to print itself

    I wanna write a C++ program that can print out the source code of the program, but this program can't be read any file.

    Can anyone give me some hints?
    thx!!

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    I think Salem had a sig that did this.....at least I think it was him......I'll have a root around to see if I still have it...

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    Like so
    Code:
    char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
    Ok, so it's C
    If you want to know more - such programs are called quines
    http://www.google.com/search?q=quine

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    He he...thats cool.....

    I remember when I compiled it and sat scratching my head as the code was being spat back out at me.....

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