473,574 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to understand this line of c ?

main(_){for(--_;putchar(_++["J!Mpwf!Zpv \1"]-1););}

Dec 31 '05 #1
56 2809
"lnzju" <ge*******@gmai l.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
main(_){for(--_;putchar(_++["J!Mpwf!Zpv \1"]-1););}


Don't. It's rubbish.
--
Ivan Budiselic
ICQ# 104044323
IRC: buda @ #gamer.hr@quake net
remove 'remove' for reply
Dec 31 '05 #2
lnzju wrote:
main(_){for(--_;putchar(_++["J!Mpwf!Zpv \1"]-1););}


Some hints:

* Write the program with the correct tabulation
* Take into account that usually main parameters are argc and argv, but
they can be called with any name. And, if type is not declared K&R
assumes int.
* _ can be the name of a variable.
* Split "for" in its parts: a for statement is divided in
initialization, continue condition and update of state. The first one
and third ones can be empty.
* putchar returns the character written as unsigned int
* integer applied to string returns n-th element. (this is something I
do not know why).

Kind regards.

Dec 31 '05 #3
Ivan Budiselic wrote:
"lnzju" <ge*******@gmai l.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
main(_){for(--_;putchar(_++["J!Mpwf!Zpv \1"]-1););}


Don't. It's rubbish.


Well it ain't rubbish cause it is valid C!!
Try compiling it..

The output will be:

I Love You

But this code is obfuscated.... Only the real C gurus will understand it
I Guess.... not this novice guy...

Broeisi
Dec 31 '05 #4
Even when "gcc" compiled with the flags -ansi and -pedantic, it
produces no errors nor warnings. Only with -std=c99 it produces 3
warnings.

Dec 31 '05 #5
"Broeisi" <br*******@gmai l.com> wrote in message
news:Q-*************** *************** @casema.nl...
Ivan Budiselic wrote:
"lnzju" <ge*******@gmai l.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
main(_){for(--_;putchar(_++["J!Mpwf!Zpv \1"]-1););}

Don't. It's rubbish.


Well it ain't rubbish cause it is valid C!!
Try compiling it..

The output will be:

I Love You


Maybe on your machine. Certainly not on all.
But this code is obfuscated.... Only the real C gurus will understand it
I Guess.... not this novice guy...


There's nothing guruesque about it.

--
Ivan Budiselic
ICQ# 104044323
IRC: buda @ #gamer.hr@quake net
remove 'remove' for reply
Dec 31 '05 #6

"lnzju" <ge*******@gmai l.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
main(_){for(--_;putchar(_++["J!Mpwf!Zpv \1"]-1););}


Here it is a little clearer [hopefully?]

#include <stdio.h>

// x will be 1 (the name of this app would be in argv[0]) if we
// don't invoke the app with some args.
//
main(x)
{
char c;

// zero then!
//
--x;

while(c = "J!Mpwf!Zpv \1"[x])
{
// No need for the -1 if we add 1 to the literal's characters...
//
// "I Love You\1"
//
c = c - 1;

x++;

putchar(c);
}
}
Dec 31 '05 #7

"lnzju" <ge*******@gmai l.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
main(_){for(--_;putchar(_++["J!Mpwf!Zpv \1"]-1););}


Ah, but run it with some params, and it's dissapointing. Perhaps the
initialiser in the for loop would have been better this way?

for(_^=_; putchar(_++["J!Mpwf!Zpv \1"]-1); );
Dec 31 '05 #8
"lnzju" <ge*******@gmai l.com> wrote:
main(_){for(--_;putchar(_++["J!Mpwf!Zpv \1"]-1););}


The two following code fragments are equivalent:

/*-A-----------------------------------*/

#include <stdio.h>

int main(void)
{
char rubbish[] = "J!Mpwf!Zpv \1"; /* will 'print' trailing '\0' */
char *rp = rubbish;

while (*rp)
{
putchar ((*rp)-1);
rp++;
}
putchar('\n'); /* not in original code */
}

/*-B-----------------------------------*/

#include <stdio.h>

int main(void)
{
char rubbish[] = "I Love You\0"; /* '\0' is redundant here */
char *rp = rubbish;

while (*rp)
{
putchar(*rp);
rp++;
}
putchar('\n'); /* not in original code */
}

/*-------------------------------------*/
Dec 31 '05 #9
Broeisi wrote:
Ivan Budiselic wrote:
"lnzju" <ge*******@gmai l.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
main(_){for(--_;putchar(_++["J!Mpwf!Zpv \1"]-1););}
Don't. It's rubbish.


Well it ain't rubbish cause it is valid C!!


Actually, it's not. In C main either takes no arguments or two
arguments, not 1.
Try compiling it..

The output will be:

I Love You
Not necessarily. It was written assuming ASCII, and not all C
implementations use ASCII.
But this code is obfuscated.... Only the real C gurus will understand it
I Guess.... not this novice guy...


Depends. It's not that difficult. Just format it properly and learn a
couple of tricks and it is simple.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Dec 31 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
1767
by: Simon Mansfield | last post by:
I have been given a list of exercises to do by my tutor, one of which is this: http://www.cems.uwe.ac.uk/~amclymer/Software%20Design%20and%20C++/Exercises/Exercise%208/Exercise.html Which i am finding very difficult to understand what is required and how exactly to do it.. Any thoughts/idea's will be greatfully recieved! Global_Inferno
3
5021
by: orekinbck | last post by:
Hi There I'm probably missing something fundamental here but I don't understand the code in the OnThreadException routine, which is found in MSDN under the topic: Application.ThreadException Event I think the whole OnThreadException routine could be replaced with two lines of code: if (ShowThreadExceptionDialog(t.Exception) ==...
8
1790
by: Charles | last post by:
I do not understand why I am getting a "Specified cast is not valid" error, since it has worked before. Something has changed and I am not really sure what it could be. I am looking for something along the lines of did you check this, have you did this, or this is the wrong way of doing this. I can access the CColPositions and the CPosition...
6
1900
by: Yan | last post by:
Here is the code: class A {}; void (A::*A) (); // Line 3 int main() { A a; // Line 6 return 0; }
24
1718
by: sonnystarks | last post by:
Created: http://www.websitesamples.j-starks.com/bio/ and attempted XHTML Transitional validation. Came up with 13 errors that do not make sense. Please do same and tell me what it is asking for, for example, on line 29, column 25: <hr width="50" noshade />. Is it telling me to eliminate the space between the letter "e" and the "/"? Is it...
54
3364
by: smnoff | last post by:
Below is a section from string.c at this linkhttp://cvs.opensolaris.org/source/xref/on/usr/src/common/util/string.cthat I am trying to fully understand.I don't fully understand LINE 514; not to mention that entire inner while loop and what it'strying to accomplish. I figured that if I can at least understand each line of this strstr methodand...
2
1843
by: Sean Hammond | last post by:
Anyone understand this? Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02) on linux2 Type "help", "copyright", "credits" or "license" for more information. .... """Send 'input' (string) to the markdown perl script, and return the .... output from markdown (string). .... .... input: a string of markdown-formatted text,...
2
2193
by: hellt | last post by:
HI all, i found winreg module from http://www.rutherfurd.net/python/winreg/index.html very useful and simple, instead _winreg. But i have a problem with this module, in its iterable part. look at the following code key = Key(HKLM,r"SYSTEM\CurrentControlSet\Services\Tcpip\Enum") for i in key.values: print i.value
4
1956
by: hirsh.dan | last post by:
i have a functions that writes information to a file. inside that function i have a line in which i call another function. if this line is executed, nothing is written to the file, but if i remark that line, it is written. i wanna understand what's wrong and fix it, but can't find what is wrong. also this line is mandatory in my code. the...
5
2584
by: Thierry | last post by:
Hello fellow pythonists, I'm a relatively new python developer, and I try to adjust my understanding about "how things works" to python, but I have hit a block, that I cannot understand. I needed to output unicode datas back from a web service, and could not get back unicode/multibyte text before applying an hack that I don't understand...
0
7832
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7747
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8093
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6498
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3768
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3785
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1364
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1094
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.