Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Anyone able to understand this C program?

Reply
Thread Tools

Anyone able to understand this C program?

 
 
ssubbarayan
Guest
Posts: n/a
 
      09-16-2005
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

 
Reply With Quote
 
 
 
 
Roberto Waltman
Guest
Posts: n/a
 
      09-16-2005
On 16 Sep 2005 06:44:46 -0700, "ssubbarayan" <(E-Mail Removed)> 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. ]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not able to display color in excel not able to display color in excel using xml sed_y XML 0 02-15-2012 09:46 PM
Debugging a Perl(SNMP-NPAdmin) module - Not able to understand fewLOC karthikd Perl Misc 2 06-18-2009 12:16 PM
Read all of this to understand how it works. then check around on otherRead all of this to understand how it works. then check around on other thelisa martin Computer Support 2 08-18-2005 06:40 AM
is anyone able to access this group from outlook express newsgroups view? A. Yarrington Cisco 3 11-25-2003 05:24 PM
Anyone able to access this site? TIA JuanMa Firefox 1 08-09-2003 06:25 PM



Advertisments