Anyone able to understand this C program?

Discussion in 'C Programming' started by ssubbarayan, Sep 16, 2005.

  1. ssubbarayan

    ssubbarayan Guest

    Gurus,
    One of my friend mailed me this sample piece of code:
    #include <stdio.h>
    main()
    {
    int a,b,c;
    int count = 1;
    for (b=c=10;a="- FIGURE?, UMKC,XYZHello Folks,\
    TFy!QJu ROo TNn(ROo)SLq SLq ULo+\
    UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
    NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
    HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
    T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
    Hq!WFs XDt!" [b+++21]; )

    for(; a-- > 64 ; )
    putchar ( ++c=='Z' ? c = c/ 9:33^b&1); return 0;
    }

    I compiled the above program with visual studio and got a map of india
    printed on the output screen.
    I am underloss to understand how this program works.This seems cryptic
    to me.Iam wondering whether those char in for loop of (b=c=10;a=....)
    is ascii char?

    This is not definitely a homework as some might think.Jus for my
    curiosity would like to know abt this.

    Advanced thanks for all your replys,
    Regards,
    s.subbarayan
    ssubbarayan, Sep 16, 2005
    #1
    1. Advertising

  2. On 16 Sep 2005 06:44:46 -0700, "ssubbarayan" <> wrote:
    >#include <stdio.h>
    >main()
    >{
    >int a,b,c;
    >int count = 1;
    >for (b=c=10;a="- FIGURE?, UMKC,XYZHello Folks,\
    > TFy!QJu ROo TNn(ROo)SLq SLq ULo+\
    > UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
    > NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
    > HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
    > T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
    > Hq!WFs XDt!" [b+++21]; )
    >
    >for(; a-- > 64 ; )
    > putchar ( ++c=='Z' ? c = c/ 9:33^b&1); return 0;
    >}
    >
    >I compiled the above program with visual studio and got a map of india
    >printed on the output screen.
    >I am underloss to understand how this program works.This seems cryptic
    >to me.Iam wondering whether those char in for loop of (b=c=10;a=....)
    >is ascii char?


    Talk about readable code...

    (a) The values in the character string encode the length of blocks of
    consecutive spaces or '!' as the difference between their value and
    the character '@' (ASCII 64)

    (b) The first line in the string is just to confuse the enemy. The
    '[b++ + 21]' skips the firs 31 characters.

    (c) 33^b&1 is equal to either ' ' or '!' depending if b is even or
    odd. The actual value of b is meaningless.

    (d) All the characters in the string less than '@' do not produce any
    output, but some of them are necessary to keep the odd/even value of b
    in sync.

    (e) c is used as a column counter, running from 10 ('\n') to 90 ('Z'),
    that is 80 columns. It fills a double role being sent as the newline
    character every time it is reset to 10.

    (f) count is not used.

    A slightly less cryptic version follows.

    #include <stdio.h>

    #define MAX_COLUMN 81

    char map_data[] =
    "TFy!QJu ROo TNn(ROo)SLq SLq ULo+"
    "UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^"
    "NBELPeHBFHT}TnALVlBLOFAkHFOuFETp"
    "HCStHAUFAgcEAelclcn^r^r\\tZvYxXy"
    "T|S~Pn SPm SOn TNn ULo0ULo#ULo-W"
    "Hq!WFs XDt!";

    main()
    {
    int a,b;
    int column;
    char *map_ptr;

    b = 0;
    column = 1;

    for (map_ptr = map_data;
    a = *map_ptr;
    map_ptr++
    )
    {
    b = !b;
    while (a-- > '@')
    {
    column++;
    if (column == MAX_COLUMN)
    {
    putchar('\n');
    column = 1;
    }
    else
    {
    if (b % 2)
    {
    putchar (' ');
    }
    else
    {
    putchar ('!');
    }
    }
    }
    }
    }


    Roberto Waltman

    [ Please reply to the group, ]
    [ return address is invalid. ]
    Roberto Waltman, Sep 16, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rico Alexander
    Replies:
    0
    Views:
    320
    Rico Alexander
    Aug 20, 2004
  2. Alan Silver
    Replies:
    0
    Views:
    453
    Alan Silver
    Nov 16, 2005
  3. Mahendra Chaurasia
    Replies:
    0
    Views:
    334
    Mahendra Chaurasia
    Jun 9, 2011
  4. sed_y
    Replies:
    0
    Views:
    1,011
    sed_y
    Feb 15, 2012
  5. karthikd
    Replies:
    2
    Views:
    149
    karthikd
    Jun 18, 2009
Loading...

Share This Page