Thread: check this code out

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    21

    check this code out

    #include<conio.h>
    #include<stdio.h>

    void main()
    {
    int a,b,c;
    for (b=c=10;a="Coming Soon\
    !BBKBKBKBKBBGBBK\
    !BBBCACBBBGBBBI!B!EAE!BBGBBBI\
    BBBCACBBBGBBBI!B!EAE!BBGBBBI\
    BBBCACBBBGBBBI!B!EAE!BBGBBBI\
    BBBCACBBBGBBBI!B!EAE!BBGBBBI\
    BBBCACBBKBKB!EAE!BBGBBK\
    !BBBGBBBI!BBI!B!EAE!BBGBB!HC\
    !BBBGBBBI!BBI!B!EAE!BBGBB!HC\
    !BBBGBBBI!BBI!B!EAE!BBGBB!HC\
    !BBBGBBBI!BBI!B!EAE!BBGBB!HC\
    !BBBGBBBI!BKB!EAE!BKBK"[b+++1]; )
    while(a-->64) putchar (++c=='Z'?c=c/9:33^b&1);
    getch();
    }


    tell me how it works ?
    i will post the ans tomm
    this was a question that i had asked in our college C-puzzles contest,so try it out
    it might be easy for some

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1) #include<conio.h>

    Needlessly included header. Really just a waste.

    2) void main()

    Entirely incorrectly. There is no such thing as 'void main' in C. Read the FAQ. This is undefined behavior.

    3) [b+++1]

    Welcome to the world of undefined behavior.

    4) }

    No return statement, which would be correct if this was actually Java.

    Go play in the obfuscated code contest if you want more horrible code. Or just hang around here, we see a lot.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>#include <conio.h>
    >>Needlessly included header.
    For this program it's (probably) needed, it's using getch(). Even so, it's still pointless when a standard function can do the same job (almost).

    >>[b+++1]
    >>undefined behavior
    Not undefined, just unusual. It's actually:
    >>[b++ +1]

    >>Go play in the obfuscated code contest
    Agreed. Personally, I don't see how this type of code actually teaches you anything worth knowing.

    >>this was a question that i had asked in our college C-puzzles contest
    I pity you. Your college teaches "void main"? - get a new one
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    ___
    Join Date
    Jun 2003
    Posts
    806
    >>Entirely incorrectly. There is no such thing as 'void main' in C. Read the FAQ. This is undefined behavior.



    Why does everyone insist that void main is incorrect in C? last weekend i went to a bookstore and scanned through about 10 different C books all of which used void main for the first half at least. Is this no void main thing something you learn once you are some magic "uber coder" or something? Because I have yet to find a C book that doesnt use void main for a good bit..

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Is this no void main thing something you learn once you are some magic "uber coder" or something?<<
    Oh yeah, there's a whole cult thing going on too.

    >>Why does everyone insist that void main is incorrect in C?
    It's incorrect to promote it when attempting to teach a standard coding practice, as it's results are undefined in nature.

    Now, enough of void main... please If you're interested, there are plenty of threads on it in here, and on the web (try googling for it).
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    ___
    Join Date
    Jun 2003
    Posts
    806
    Oh So its sort of like a little cheat that you can do or something?
    "When I die I want to pass peacefully in my sleep like my grandfather did, not screaming and yelling like the passengers in his car."

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Oh So its sort of like a little cheat that you can do or something?
    No, it's not a "cheat". Under certain conditions it is acceptable coding, but in general (and by that I really mean for the purposes of posting on forums like these), it is not acceptable.

    Compile/run this program, and see what value it returns to the OS:
    Code:
    void main(void)
    {
    }
    Whatever value it gives you, has the potential of being different to what it gives me.

    [edit] I take it Quzah is on the phone again. Posting on the wrong thread, I dunno
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Hammer
    [edit] I take it Quzah is on the phone again. Posting on the wrong thread, I dunno
    *grin* I have no idea what you're talking about?

    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    Under dos, using "void main" can give weird errors upon program termination as, like other have said, the return code is undefined, and if you happen to hit a used one, you can get a nice error message.

    As for the code at the top of this thread however, I fail to see what use it is. Nothing can be learnt from it and it's not going to get you anywhere knowing how it works. To be honest, I think it's pretty childish and it's obvious the author thinks he part of some "leet" group.

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by _Elixia_
    To be honest, I think it's pretty childish and it's obvious the author thinks he part of some "leet" group.
    The author was probably trying to do something similar to what you'll find here. Trying to be 31337 or not remains unanswered. However, you'll find that there are some damn impressive entries on said link.

    Some are just truly horrible to look at, which is the intent, but some of them are truly pieces of art.

    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>similar to what you'll find here.
    And that is the place for obfuscated code, not a college test paper.

    >>some of them are truly pieces of art.
    Yeah, I agree, there is some real neat stuff. I had one I was going to link to, but I can't find it now
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Hammer
    >>some of them are truly pieces of art.
    Yeah, I agree, there is some real neat stuff. I had one I was going to link to, but I can't find it now
    Nifty.
    Reminds me of an old BBS logo or something...

    I could go on and on ...

    I gave up looking before I found the one I was really looking for... Oh well... You get the idea.

    Quzah.
    Hope is the first step on the road to disappointment.

  13. #13
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Originally posted by _Elixia_
    As for the code at the top of this thread however, I fail to see what use it is. Nothing can be learnt from it and it's not going to get you anywhere knowing how it works.
    But it doesn't work. Upon compiling it, I got 3 Warnings and 1 Error.

    "One cannot know how something works if the something doesn't work" -- me
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by WaltP
    But it doesn't work. Upon compiling it, I got 3 Warnings and 1 Error.
    Just looking at it you can tell it won't work. Code tags would have made it obvious:
    Code:
    for ( 
        b=c=10 ; /* 1 ; */
    
         a="Coming Soon\
        !BBKBKBKBKBBGBBK\
        !BBBCACBBBGBBBI!B!EAE!BBGBBBI\
        BBBCACBBBGBBBI!B!EAE!BBGBBBI\
        BBBCACBBBGBBBI!B!EAE!BBGBBBI\
        BBBCACBBBGBBBI!B!EAE!BBGBBBI\
        BBBCACBBKBKB!EAE!BBGBBK\
        !BBBGBBBI!BBI!B!EAE!BBGBB!HC\
        !BBBGBBBI!BBI!B!EAE!BBGBB!HC\
        !BBBGBBBI!BBI!B!EAE!BBGBB!HC\
        !BBBGBBBI!BBI!B!EAE!BBGBB!HC\
        !BBBGBBBI!BKB!EAE!BKBK"[b+++1]
        while(a-->64)
        putchar(++c=='Z'?c=c/9:33^b&1)
        ; /* 2 ; */
    
        /* uh oh. where is the ) on the for( */
    
        getch();
    }
    The for loop is incomplete.

    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    There, I fixed the OP's post, I put a space between the ; and the )
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code Check
    By Dae in forum C++ Programming
    Replies: 12
    Last Post: 01-08-2009, 07:01 PM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  3. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Game Programming
    Replies: 0
    Last Post: 10-14-2002, 01:27 PM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum C# Programming
    Replies: 0
    Last Post: 10-14-2002, 01:26 PM
  5. Check my code Please
    By AdioKIP in forum C++ Programming
    Replies: 1
    Last Post: 03-12-2002, 08:52 PM