can YOU tell what this program does??

This is a discussion on can YOU tell what this program does?? within the C++ Programming forums, part of the General Programming Boards category; a prof showed me this code, its kind of neat... take a guess at what the output of this code ...

  1. #1
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640

    can YOU tell what this program does??

    a prof showed me this code, its kind of neat...

    take a guess at what the output of this code is before you compile and run it, its interesting. post your guess first then see how close you were!!


    Code:
     main(){char*a="main(){char*a=%c%s%c;print(a,34,a,34,10);}%c";printf(a,34,a,34,10);}

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    displays main(){char*a=%c%s%c;print(a,34,a,34,10);}%c";prin tf(a,34,a,34,10);}

  3. #3
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Originally posted by revelation437
    displays main(){char*a=%c%s%c;print(a,34,a,34,10);}%c";prin tf(a,34,a,34,10);}
    Actually, it displays:
    Code:
    main(){char*a="main(){char*a=%c%s%c;print(a,34,a,34,10);}%c";print(a,34,a,34,10);}

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    hmm, pretty cool stuff. i didnt know they were called 'quines'

  5. #5
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    Quines are just programs that print out their own source code. You can even have a "Null Quine."

    Null Quine-
    Code:
     

  6. #6
    cereal killer dP munky's Avatar
    Join Date
    Nov 2002
    Posts
    655
    actually it wont print anything

    C:\blah.cpp(7) : error C2065: 'print' : undeclared identifier
    guns dont kill people, abortion clinics kill people.

  7. #7
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Originally posted by dP munky
    actually it wont print anything

    C:\blah.cpp(7) : error C2065: 'print' : undeclared identifier
    hmmm. thats weird, works for me.

  8. #8
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    Originally posted by dP munky
    actually it wont print anything

    C:\blah.cpp(7) : error C2065: 'print' : undeclared identifier
    Easily explained; different compilers.

  9. #9
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Originally posted by Munkey01
    Easily explained; different compilers.
    Yeah, I guess some know to look into stdio.h by itself, and others you need to make sure you include the header. You do in MSVC++, I know that much. I think in Dev-C++, you don't, but I'm not sure...

  10. #10
    Registered User
    Join Date
    Jan 2003
    Posts
    311
    actually the quine posted has a typo, it should be:
    main(){char*a="main(){char*a=%c%s%c;printf(a,34,a, 34,10);}%c";printf(a,34,a,34,10);}
    the other important thing is that this is C, not C++, be sure to name your test file "quine.c". You will get some warnings, but it should compile.

  11. #11
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Here's a quine that is also a palindrome:
    Code:
    /**/char q='"',*a="*//**/char q='%c',*a=%c%s%c*/};)b(stup;]d[b=]d-852
    [b)--d(elihw;)q,a,q,q,2+a,b(ftnirps{)(niam;031=d tni;]952[b,",b[259];
    int d=130;main(){sprintf(b,a+2,q,q,a,q);while(d--)b[258-d]=b[d];puts(
    b);}/*c%s%c%=a*,'c%'=q rahc/**//*"=a*,'"'=q rahc/**/
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  12. #12
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    None of those should even compile. It is not valid in C++ to declare main without a returntype.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. 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