Anyone able to understand this C program?

S

ssubbarayan

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
 
R

Roberto Waltman

#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. ]
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top