?
Solved

C-Shirt design :-)

Posted on 2006-05-28
34
Medium Priority
?
784 Views
Last Modified: 2010-04-15
All,

Today's bit of fun!

Come up with a T-Shirt graffiti in real C code. The rules are as follows:

1. If the code produces a result, it must be humourous, the more obscure the better.

2. A C programmer, with a little thought, should discover at least a little humour in the code.

3. The more humour the better.

4. "Standard" C only please. It must compile and run on at least most, if not all implementations.

Note that the C does not need to be particularly good. Some exceptionally bad code could fit the bill.

Paul
0
Comment
Question by:PaulCaswell
  • 9
  • 7
  • 4
  • +6
34 Comments
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 16779799
Hi PaulCaswell,

This certainly leaves a lot to the imagination.  A single printf() that produces a saying seems blase, so it would appear that the humor is in the code.  Well, at least Sunny's code.  :)


Oh, this will rot a few minds:

   if (!True ())
     False ();
   else
     Maybe ();


Or maybe a full program that's really stupid:

#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <ctype.h>

#define print printf

int mode = 0;
char Buffer[120];
char *p;
int main ()
{
  while (fgets (Buffer, 120, stdin))
  {
    if (0==1)
//1
      print ("ing");
    do  // ne
//0
    {}
    while (0==1);
    if (memcmp (Buffer, "//0", 3) == 0)
    { mode = 0; continue; }
    if (memcmp (Buffer, "//1", 3) == 0)
    { mode = 1; continue; }

    if (mode == 1)
      for (p = Buffer; *p; ++p)
        if (isalpha (*p) || *p == '\n')
          fputc (*p, stdout);
  }
}


May this will help kickstart things.  :)

Kent
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16779876
Nice idea Paul :) Wonder what inspired you hehe

I've always enjoyed this site :

http://www.ioccc.org/main.html


I especially like this (quite famous) one :

    int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
    o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}

(an entry of the first contest in 1984, by an anonymous person :))

I'll try to come up with something of myself now heh
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16783111
Something I came across a while ago, and has been used as a "C test" ... try to understand what it does without compiling :) :

    #include  <stdio.h>

    char *c[] = { "ENTER", "NEW", "POINT", "FIRST" };
    char **cp[] = { c+3, c+2, c+1, c };
    char ***cpp = cp;

    main() {
      printf("%s", **++cpp);
      printf("%s ", *--*++cpp+3);
      printf("%s", *cpp[-2]+3);
      printf("%s\n", cpp[-1][-1]+1);
    }

If this is not ugly code, then I don't know what is lol ...

Still no good inspiration to come up with something of my own heh
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 53

Expert Comment

by:Infinity08
ID: 16783295
Ok, here's something I came up with : the goal is to find the bug in the wollowing code (if you want to keep it a tad more challenging, don't use a compiler :)) :

    #include <stdio.h>
   
    #define BUCKET 10
    #define NICE_GARDEN 4
   
    typedef enum { MAPLE = 1, LAVENDER, BLUEBERRY, ROSE, BIRCH, POPPY, AZALEA, PINE, TULIP, OAK } seeds;
   
    int result(char* garden) {
      return strlen(garden) - NICE_GARDEN;
    }
   
    int main(void) {
      char *garden[] = { "tree", "plant", "flower", "shrub" };
      int seed = BIRCH & TULIP;
      int water = BUCKET / 5;
      (result(*(garden+seed)+water)>0)?printf("woohee !!"):printf("try again ...");
      printf("\n");
      return 0;
    }

I don't know if I've hidden it too good or if it's too obvious though ... what do you thinl lol
0
 
LVL 8

Expert Comment

by:hiteshgupta1
ID: 16783530
try this one
not as good as ur programs!

#include <stdio.h>

int main() {
  int x = 1;
  int y = 1;
  int z = 1;
  printf("x(%d) == y(%d) == z(%d) ==> ", x, y, z);
  if (x == y == z) printf("true\n");
  else printf("false\n");

  x = y = z = 2;
  printf("x(%d) == y(%d) == z(%d) ==> ", x, y, z);
  if (x == y == z) printf("true\n");
  else printf("false\n");

  x = 1; y = z = 0;
  printf("x(%d) == y(%d) == z(%d) ==> ", x, y, z);
  if (x == y == z) printf("true\n");

  else printf("false\n");
return 0;
}


0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 16785387
All good! Thanks guys!

Lets see if we can find some that would fit on a T-Shirt? :-)

An emoticon or two would look good. I keep trying (_?+:-) but it doesnt want to work.

Paul
0
 
LVL 14

Expert Comment

by:cwwkie
ID: 16785551
Here is something small, but it should be improved a bit.

#include <stdio.h>
int main(){
int O=30,*_=&O;
printf("%d %% of C programmers have a problem with pointers\n",
  O-O  -  *_+   *_+   *_*   8)   ;}    /*   :))   */
0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 16786537
Hi cwwkie,

Looking good! Clever too, the use of '_'. How about something even more succinct? How about:

int O=30,*_=&O; O=  O-O  -  *_+   *_+   *_*   8)   ;}    /*   :))   */

That looks short, punchy, and has lots of smiles in it. :-)

Can anyone improve on that?

The double use of *_+ seems not to fit in a way but without it there isnt really enough to it. Can anyone think of some more emoticons we can fit in? There's a whole bunch here:

http://www.experts-exchange.com/Miscellaneous/Lounge/Q_21445662.html

Paul
0
 
LVL 7

Expert Comment

by:aib_42
ID: 16786665
#include <stdio.h>

int main(int argc, char *argv[])
{
      char msg[] = "I cannot read C code.";

      return argc + printf("%c", msg[argc==4?0:(main(argc==1?23:argc==11?7:argc-1,0)-4)]);
}
0
 
LVL 7

Expert Comment

by:aib_42
ID: 16786731
Errm, I forgot to write the non-code portion of my post:

What I'd like to see on a t-shirt is some code that does the opposite of (or something different than) what it seems to do, as all good C code does, as we all know.

This little recursive code is an extension on this idea, and I fear might be as close as I can get.

Ultimately, I'd want a piece of code as simple as:
char msg[] = "I cannot read C code.";
printf("%s", msg);
to output something like "I can read C code.", due to a comma or another simple syntax twist that cannot be easily noticed at first sight. Unfortunately, C has a rather straightforward syntax, and [I think] such a twist can only be hidden in obfuscation. (Or using the preprocessor, maybe?)
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16787937
>> Can anyone improve on that?
Dunno if it improves it, but added some more :

    #include <stdio.h>
    int main(){
    int O=30,*_=&O,o=-80,Y=10;
    printf("%d %% of C programmers have a problem with pointers\n",
      O-O  -  *_+   *_*   (Y)   ?-(   ~o   ,o)   :o)   ;}    /*   :))   */

The sole '-' bothers me a bit ... heh

It should be possible to make some kind of "story", or "scene" with the emoticons, so it doesn't even look like code ...


btw, did anyone find the bug in the code from my last post ? I'm curious :)
0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 16790280
Hi Infinity08,

A 'bug' is not a 'bug' if you intended it to happen :-)

However:

      (result(*(garden+seed)+water)>0)?printf("woohee !!"):printf("try again ...");

becomes

      (result(*(garden+1)+water)>0)?printf("woohee !!"):printf("try again ...");

becomes

      (result("plant"+5)>0)?printf("woohee !!"):printf("try again ...");

becomes

      (result("")>0)?printf("woohee !!"):printf("try again ...");

becomes

      (result("")>0)?printf("woohee !!"):printf("try again ...");

becomes

      (-4>0)?printf("woohee !!"):printf("try again ...");

becomes

      printf("try again ...");

I think?

Paul
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 16790405

Source module for Girfriend 2.x:

#include <stdlib.h>
#include <stdio.h>

Reminder ()
{
  printf ("\rGentle Reminder");
}


Upgrade to Wife 1.0:

6c6
<   printf ("\rGentle Reminder");
---
>   printf ("\rNag............");


Upgrade to Wife 1.1 (Honeymoon Over):

6c6
<   printf ("\rNag............");
---
>   printf ("\rBitch..........");



   :~}

0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16790790
@Paul :
>> I think?
BUCKET/5 equals 2, not 5 ... that should reveal the bug hehe :)

I just start to realise how disappointing it is lol ... should have come up with something better :)
0
 
LVL 85

Expert Comment

by:ozo
ID: 16792738
0
 
LVL 23

Expert Comment

by:Mysidia
ID: 16794798
Could abuse trigraphs and make things really whacky... :)


#define  Z  "%"  "c"
#define  z   Z Z Z

main() {
    char x[]  =
    "Do you speak C?\n."    Z z Z z Z z;
# define V \
          -10-10-10-1-1
   
    0 ??( x ??) =    6[z]; *
 
    x += 3;

    printf(x +  17,   x ??( 0  ??( x ??) ??) V,       9  ??( x ??),      7  ??( x ??),
                           x ??( 16 ??),
                           x ??( 16 ??),
                           x ??( 2 ??),
                           x ??( 13 ??),
                           x ??( 14 ??),
                           x ??( 14 ??),
                           x ??( 11 + 0 ??( x ??) ??),     14 ??( x ??),   15 ??( x ??), V);
  ??>
0
 
LVL 14

Expert Comment

by:cwwkie
ID: 16801087
> Could abuse trigraphs

Like that. But I'm afraid having that on your T-Shirt might look like you can't afford a t-shirt designer with a modern computer ;)
At least I have never used it since I learned C almost 15 years ago.
0
 
LVL 3

Expert Comment

by:srinims
ID: 16806752
funny things are always funny

#include <stdio.h>
int main(){
int  ______,_______,________,_________,__________,___________;
int $;

            printf("%d",$-__________-$);
            printf("%d", $*________*$ );
            printf("%d",  $+______+$   );

int ____________,_____________,______________,_______________;
}

0
 
LVL 3

Expert Comment

by:srinims
ID: 16806789
int main()
{
/*
        (*_*)      ('_')
           | ---'  '---|
          /\          /\
*/
}
even you can try this simply;
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16806813
@srinims : I'm curious ... what's the $ supposed to do ?
0
 
LVL 3

Expert Comment

by:srinims
ID: 16806846
nothing it's just a varaible;
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16806884
It's not a valid variable afaik ... only letters, digits and _ are allowed ... or am I missing something ?
0
 
LVL 3

Expert Comment

by:srinims
ID: 16806932
I haven't faced any problem in microsoft compiler.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16807227
weird ... :) oh well, never mind me :)
0
 
LVL 14

Expert Comment

by:cwwkie
ID: 16809208
> > what's the $ supposed to do ?
> I haven't faced any problem in microsoft compiler.

It seems to be Microsoft Specific in C++: http://msdn2.microsoft.com/en-us/565w213d.aspx
But not in C: http://msdn2.microsoft.com/en-us/e7f8y25b(VS.80).aspx
0
 
LVL 7

Accepted Solution

by:
aib_42 earned 2000 total points
ID: 16819054
Guess what I've wasted most of today's valuable time on:

http://aib.ftuff.com/get.php?page=C_quine
0
 
LVL 14

Expert Comment

by:cwwkie
ID: 16819409
> Guess what I've wasted most of today's valuable time on

:)

Very nice. I think it is much better than the Perl Camel T-shirt you are referring to.
0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 16819433
i aib_42,

That is AWESOME! You've gotta have full points for that one! Does it assume any particular CPU or is it cross-platform?

Thanks all! But you've got to agree its impressive and fits the question perfectly.

Paul
0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 16819808
Hi again aib,

It also has an artistic colour pattern when seen with syntax colouring! :-)

Paul
0
 
LVL 7

Expert Comment

by:aib_42
ID: 16820940
>Very nice. I think it is much better than the Perl Camel T-shirt you are referring to.
Thanks. I've also noticed for the first time today that the Perl code contains some broken-up keywords such as
"ev   al".

>That is AWESOME! You've gotta have full points for that one!
Woah, thanks :).

>Does it assume any particular CPU or is it cross-platform?
I think it's pure ANSI-C with the exception of non-left-justified preprocessor directives. (I did make sure they were on their own lines, though.) What does gcc say?
(MSVS and lcc-win32 compile without any warnings for me)

I should get a t-shirt printed while I'm still excited about this :)
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 16822697
That's indeed awesome !! When are you bringing that T-shirt on the market ? :) I'll buy it for sure !
0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 16822902
>>I'll buy it for sure !
Me too!
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 16826951


Somehow, this URL fits into this discussion really well.  Or not.    :~}


Kent


   http://www.youtube.com/watch?v=BovQyphS8kA
0
 
LVL 16

Author Comment

by:PaulCaswell
ID: 16826967
ROTFL :-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question