• Anonymous (unregistered)

    So what does this CAPTCHPA thing mean on all the posts anyway? Is it a reference to some previous article or something?

    Actually I might have just figured it out.

    CAPTCHA: muhahaha

  • Bobby Knight (unregistered)

    No.

  • Will (unregistered)

    How about using pSpaceChar as a "/t".

    Like:

    string Spacer(string a, string b, string c) {

    int N = 8; //Set the width of the tab.

    return a & pSpaceChar(N - len(a)) & b & pSpaceChar(N - len(b)) & c & pSpaceChar(N - len(c)); }

    Just hope that a, b, and c are less than 8 characters long. Hell, you could even write a check for that. Hmm, how convoluted could that check be? Nested ifs? State machine?

  • (cs)

    I use a function (rather than array) to return X spaces to help with aligning columns in a console app. Not a very exciting use, I'm afraid.

  • TonyL (unregistered)
    Expand(string expression) {
     for (int i=0; i<8; i++) {
      for (int j=0; j<expression.length(); j++) {
       printf("%s%s", expression[j], pSpaceChar[i], );
      } 
      printf("\n");
     }
    }</pre>
    

    inspiration: [image]

  • DJ Hirko (unregistered)

    How about it being a char * instead of a const char *, too? String literals are const char *'s.

  • rien (unregistered)

    the python language is famous for delimiting blocks by their indentation.

    if you try to write a python interpreter in python, you might end up writing something like this:

        space_chars = ["     ", "    ", "   ", "  ", " ", ""]
    
        line = input( ">>>" )
        for indent_spaces in space_chars:
            if line.replace( "\t", " ").startswith( indent_spaces ):
                indent_level = len( space_chars ) - space_chars.index( indent_spaces ) - 1
                break
    

    this is the most innefficient way of finding indentation ever written on earth, but a fair use of the described technique...

  • BunnyStrider (unregistered) in reply to Anonymous

    I've been wondering about the captcha too...how do you add do your word, or do you just add it in your comment for the fun of it..

  • Rob (unregistered) in reply to DJ Hirko

    In C string literals have type char *, not const char *, you just aren't allowed to modify them.

  • TimmyT (unregistered) in reply to BunnyStrider

    The Captcha was waffles dammit.

  • TheMagic8Ball (unregistered)

    It was my understanding that space was ever expanding. So pSpaceChar should not be a static array. It needs to be dynamic to account for more space.

  • (cs)

    Why, I use that exact code to display my Christmas tree every year!

    #include <stdio.h>
    #include <stdlib.h>
    
    char *pSpaceChar[8] = {
          "",             // No Space Characters
          " ",            // One Space Character
          "  ",           // Two Space Characters
          "   ",          // Three Space Characters
          "    ",         // Four Space Characters
          "     ",        // Five Space Characters
          "      ",       // Six Space Characters
          "       " };    // Seven Space Characters
    
    char *pStarChar[8] = {
          "",             // No Star Characters
          "*",            // One Star Character
          "**",           // Two Star Characters
          "***",          // Three Star Characters
          "****",         // Four Star Characters
          "*****",        // Five Star Characters
          "******",       // Six Star Characters
          "*******" };    // Seven Star Characters
    
    int main()
    {
            int i;
            for(i=0;i<8;i++)
            {
                    printf("%s%s%s%s\n",pSpaceChar[7-i],pStarChar[i],pStarChar[i],pSpaceChar[7-i]);
            }
            for(i=0;i<2;i++)
            {
                    printf("%s%s%s%s\n",pSpaceChar[7-1],pStarChar[1],pStarChar[1],pSpaceChar[7-1]);
            }
            printf("Merry Christmas!\n");
    }
    
    
    
          **
         ****
        ******
       ********
      **********
     ************
    **************
          **
          **
    Merry Christmas!
    
  • (cs)

    How about using it as a multiplication teaching tool? You could also make some really gross uses of the old VB String function.

    What's 5*5 kids? hmmm: String(5, pSpaceChar[5]) == String(25, " ")

  • Jeff Alexander (unregistered)

    Perhaps it could be used as part of a code generator for the Whitespace language. Something like Add being equivalent to pSpaceChar[2].

    http://compsoc.dur.ac.uk/whitespace

  • (cs)
    //need to print out the cube of all numbers from 0 to 99
    //right-aligned
    for (int i=0;i<100;i++)
    {
      int cubed_value= i * i * i;
      std::string str_value = convertTo<string>(cubed_value);
      //print the value right aligned..
      cout << pSpaceChar[7-str_value.size()] << str_value << "\n";
    }
    
  • Spoe (unregistered)

    Why not this?

    sprintf(pDuration, "%-*s", pPointer, ((9 - iLength) * 2) + strlen(pPointer));

    Or:

    sprintf(pDuration, "%*s%s", " ", (9-iLength) * 2, pPointer);

    Oh, I know, I know, not what we were looking for. We were looking for ways to use pSpaceChar.

  • Anonymous coward (unregistered) in reply to Anonymous

    The code is bugged. It should look that way:

      char *pSpaceChar[8] = {
          "",             // No Space Characters
          " ",            // One Space Character
          "  ",           // Two Space Characters
          "    ",         // Two Space Characters - fixed for customer #4424
          "    ",         // Four Space Characters
          "     ",        // Five Space Characters
          "      ",       // Six Space Characters
          "-1" };         // Seven Space Characters - fixed for bug #32345
  • Martin (unregistered)

    Obviously, this only makes sense when combine with other WTFs.

    function SuperMan( int x )
    {
    	int i;
    	
    	for ( i == 0; i < x; i++ )
    	{
    		switch (i)
    		{
    			case 0: return strlen( pSpaceChar[i] );
    			case 1: return strlen( pSpaceChar[i] );
    			case 2: return strlen( pSpaceChar[i] );
    			case 3: return strlen( pSpaceChar[i] );
    			case 4: return strlen( pSpaceChar[i] );
    			case 5: return strlen( pSpaceChar[i] );
    			case 6: return strlen( pSpaceChar[i] );
    			case 7: return strlen( pSpaceChar[i] );
    			
    			default:
    				return MAYBE;
    		}
    	}
    }
    
  • (cs)

    Pfft - this needs to be migrated to a J2EE Platform.

    I offer forth the WhiteSpaceGenerator! It's even thread-safe!

    public class WhitespaceGenerator {
    
       public static String[] whitespaces = new String[] {
          "",
          " ",
          "  ",
          "   ",
          "    ",
          "     ",
          "      ",
          "       ",
          "        "
       };
    
       public static String getWhitespace(int thisManySpaces) {
          StringBuffer sb = new StringBuffer();
          synchronized (whitespaces) {
             while ( thisManySpaces >= (whitespaces.length-1) ) {
                sb.append(whitespaces[whitespaces.length-1]);
                thisManySpaces -= (whitespaces.length-1);
             }
             sb.append(whitespaces[thisManySpaces]);
          }
          return sb.toString();
       }
    }
    
  • Anonymous (unregistered)

    Hmm, 8 different strings... Surely this is some (even more!) esoteric dialect of brainfuck?

  • (cs) in reply to rien
    rien:
    if line.replace( "\t", " ").startswith( indent_spaces )
    
    HAH!

    YOU WISH! (I'm pretty sure the standard CPython interpreter considers a \t to be equivalent to 8 spaces)

  • n (unregistered) in reply to Martin
    Martin:
    Obviously, this only makes sense when combine with other WTFs.
    function SuperMan( int x )
    {
    	int i;
    	
    	for ( i == 0; i < x; i++ )
    	{
    		switch (i)
    		{
    			case 0: return strlen( pSpaceChar
    ...			
    			default:
    				return MAYBE;
    		}
    	}
    }
    

    this one gets my vote so far.

  • (cs)

    Isn't it obvious! Someone is trying to create an octal calculator. Just define an array of char * pointers long enough to hold the number you want, and set each pointer to the relevant element in the spaces array. For example

    char *Number1[MAXDIGITS] = {pSpaceChar[4], pSpaceChar[2], ""}; //024 char *Number2[MAXDIGITS] = {pSpaceChar[7], pSpaceChar[5], ""}; //057 char *Number3[MAXDIGITS] = {""};

    Addition is performed by concatenation, followed by reducing the length by 8 & carrying pSpaceChar[1], if necessary.

    const int MAXDIGITS = 3;
    int Add (char **result, char **num1, char **num2);
    
    
    char *pSpaceChar[8] = {
          "",             // No Space Characters
          " ",            // One Space Character
          "  ",           // Two Space Characters
          "   ",          // Three Space Characters
          "    ",         // Four Space Characters
          "     ",        // Five Space Characters
          "      ",       // Six Space Characters
          "       " };    // Seven Space Characters
    
    int main() 
    {
    
    	char *Number1[MAXDIGITS] = {pSpaceChar[4], pSpaceChar[2], pSpaceChar[0]};
    	char *Number2[MAXDIGITS] = {pSpaceChar[7], pSpaceChar[5], pSpaceChar[0]};
    	char *Number3[MAXDIGITS] = {pSpaceChar[0],pSpaceChar[0],pSpaceChar[0]};
    
    	Add(Number3, Number1, Number2);
    
    	return 0;
    
    }
    
    
    int Add (char **result, char **num1, char **num2)
    {
    	char Sum[15] = "";
    	int carry = 0;
    	int val = 0;
    	
    	for (int j=0; j<MAXDIGITS; j++)
    	{
    		val = sprintf(Sum, "%s%s%s", num1[j], num2[j], result[j]);
    		
    		if (val > 7)
    		{
    			result[j] = pSpaceChar[val-8];
    			if (j==MAXDIGITS-1)
    				carry = 1;
    			else
    			  result[j+1] = pSpaceChar[1];
    		}
    		else
    			result[j] = pSpaceChar[val];
    			
    		memset(Sum, 0, 15);
    	}
    	
    	return carry;
    }	
    

    Subtraction is just reverse addition. Other operators left up to the reader.

    I'd go into more detail but lunch break is over.

    Disclaimer: Hey - I wrote the code above quickly. Forgive any WTFs, please.

  • AP (unregistered)

    Perhaps this is used in source code generator for the Whitespace programming langauge.

  • newt0311 (unregistered) in reply to Rob
    Rob:
    In C string literals have type char *, not const char *, you just aren't allowed to modify them.
    no, char * are perfectly modifiable. Its done all the time. all that a char * means is an array of characters and is the closest C comes to a string. a const char * is also a valid declaration which will cause the compiler to raise an error if any attempt is made to modify it. gcc also gives a warning when a const is assigned to a non-const without a specific declaration to go along with it.
  • ort (unregistered) in reply to DJ Hirko

    Technically they are char[N]

  • n (unregistered) in reply to n

    i am a total tard and can't format comments. "this one gets my vote so far" should have been outside of the quote. kill me.

  • JohnB (unregistered) in reply to Anonymous coward
    Anonymous coward:
    The code is bugged. It should look that way:
      char *pSpaceChar[8] = {
          "",             // No Space Characters
          " ",            // One Space Character
          "  ",           // Two Space Characters
          "    ",         // Two Space Characters - fixed for customer #4424
          "    ",         // Four Space Characters
          "     ",        // Five Space Characters
          "      ",       // Six Space Characters
          "-1" };         // Seven Space Characters - fixed for bug #32345

    This is quite likely the drollest comment that has ever appeared here. Absolutely delightful!

  • (cs)

    The only combination of factors that could be attributed to this code:

    1. Very specifically formatted outputs
    2. Poor understanding of a language
    3. Slight intellectual impairment or alcohol
  • Trinian (unregistered)

    char *pSpaceCount[8] = { ... " ", // One Space Character, AH AH AH! " ", // Two Space Characters, AH AH AH! " ", // Three Scintillating Space Characters, AH AH AH! ... };

  • nobody (unregistered)

    As I think some commenters have been trying to say, this would be useful for converting tabs to spaces. 8-printPos%8 would give the number of spaces to add to go to the next tab after printPos (assuming printPos is positive, and you really want to go to the next tab if it is already at a tab), and instead of adding that number of spaces, just index into this array.

    Not that it would save much time, but it isn't that much of a WTF if it is used that way.

  • (cs) in reply to TonyL

    TonyL,

    Ha, I got that same forward just this morning. I thought the elephant one was hilarious also.

  • JBQ (unregistered)

    I guess they don't know about the %.*s printf format...

  • (cs)

    Well, perhaps I'm wtfing. I did this a couple months ago. (not global)

    ...
    char acRec[100];
    char *pDashes = "----------------------------------------"
                    "----------------------------------------";
    char *pSpaces = "                                        "
                    "                                        ";
    ...
    sprintf(acRec, "/*%.66s*/", pDashes);
    COMM_sMsg(pJcl, 34, 1, RC00, acRec);
    
    ...
    
    sprintf(acRec, "/*%.66s*/", pSpaces);
    COMM_sMsg(pJcl, 37, 1, RC00, acRec);
    
    sprintf(acRec, "/*%.25s%-16s%.25s*/",
            pSpaces, "Activity Report", pSpaces);
    COMM_sMsg(pJcl, 38, 1, RC00, acRec);
    
    sprintf(acRec, "/*%.66s*/", pSpaces);
    COMM_sMsg(pJcl, 39, 1, RC00, acRec);
    ...
    

    If I'm WTFing here, let me know. I personally thought it was better than what this was written to replace (which just put the dashes and spaces inline, repeated 600 times), but if there's a still better way, I'll be glad to hear it.

    Other WTF's are probably evident from this code ("why not just write a formatting function?", "Those incrementing numbers.. are they for a purpose as stupid as they seem to be?", "What the hell is an RC00...? is that a named constant for a specific literal number??", "Why are you outputting what looks like C comments in the first place?", etc), but I'd like to think those aren't mine. The use of pSpaces/pDashes itself, I don't see a problem with.

    As for using an array, that's just stupid. Were I to do what was being done in the supplied code, I'd probably go with something like:

    char *pSpaces = "                                        "
                    "                                        ";
    
    #define SPACE(n) (&(pSpaces[80-(n)]))
    
  • HappyPanda (unregistered) in reply to Martin
    Martin:
    Obviously, this only makes sense when combine with other WTFs.
    function SuperMan( int x )
    {
    	int i;
    	
    	for ( i == 0; i < x; i++ )
    	{
    		switch (i)
    		{
    			case 0: return strlen( pSpaceChar[i] );
    			case 1: return strlen( pSpaceChar[i] );
    			case 2: return strlen( pSpaceChar[i] );
    			case 3: return strlen( pSpaceChar[i] );
    			case 4: return strlen( pSpaceChar[i] );
    			case 5: return strlen( pSpaceChar[i] );
    			case 6: return strlen( pSpaceChar[i] );
    			case 7: return strlen( pSpaceChar[i] );
    			
    			default:
    				return MAYBE;
    		}
    	}
    }
    

    You forgot to define MAYBE. I suggest:

    MAYBE = "true"

  • StupidGuy (unregistered)

    The real WTF is the unreadability...

    I think "5[pSpaceChar]" would be better readable than "pSpaceChar[5]";

    Back to the example.. It's just a form of loop-unrolling... Defining often used data first... Classic optimisation :-)

  • Jailors Suit Ya (unregistered)

    pSpaceChar is the toilet.

  • dkf (unregistered) in reply to newt0311
    newt0311:
    Rob:
    In C string literals have type char *, not const char *, you just aren't allowed to modify them.
    no, char * are perfectly modifiable.
    But Rob was talking about string literals, which are often in read-only memory (irrespective of what the type decorations say...)
  • Rob (unregistered) in reply to newt0311
    newt0311:
    Rob:
    In C string literals have type char *, not const char *, you just aren't allowed to modify them.
    no, char * are perfectly modifiable.

    Try re-reading my post, I said string literals couldn't be modified.

  • (cs) in reply to Anonymous
    Anonymous:
    So what does this CAPTCHPA thing mean on all the posts anyway? Is it a reference to some previous article or something?
    It's an intelligence test. Anyone who includes their captcha in their post, fails.
  • BitTwiddler (unregistered) in reply to HappyPanda

    No, no, no...

    The default case should return FILE_NOT_FOUND. Don't you people know ANYTHING about programming???

  • (cs) in reply to Zylon
    Zylon:
    It's an intelligence test. Anyone who includes their captcha in their post, fails.

    I'd say anyone who includes it would pass with a D+. Anyone who tries to make a clever quip about their captcha FAILS.

    Captcha: Cognac. At this time of the morning?! It's is early but I guess I will drink some!! ROFL

  • anonymous guy (unregistered)

    I think the best use would be as an entry in a personnel file listing reasons for termination. You know, exceeded sick leave and doesn't show up for work, when he does show up he's drunk, and the following code. That way he doesn't get unemployment compensation.

    Actually, I liked the Christmas Tree. If there's a prize, give it to him.

  • Rob (unregistered) in reply to TonyL

    hah hah! Loved this one.

  • anonymous (unregistered)

    here's my captcha:

                  /´¯/) 
                ,/¯  / 
               /    / 
         /´¯/'   '/´¯¯·¸ 
      /'/    /    /    /¨¨/¯\ 
     ('(    ´    ´     ¯ ;/'  ') 
      \                 '     / 
       '\'   \           _.·´ 
         \              ( 
           \             \ 
    
  • foo (unregistered)

    A construct like this:

          char *pSpaceChar[8] = {
              "",             // No Space Characters
              " ",            // One Space Character
              "  ",           // Two Space Characters
              "   ",          // Three Space Characters
              "    ",         // Four Space Characters
              "     ",        // Five Space Characters
              "      ",       // Six Space Characters
              "       " };    // Seven Space Characters
    
    

    can be used for any base 7 arithmetic that you might imagine. What we have defined for us here is a representation of the numbers 0 through 7 which is Octal. So I have written a decimal to octal converter...

    My example in Java since my C is quite rusty...

    public class OctalConverter {
       public static String[] spaceArray = new String[] {
          "",
          " ",
          "  ",
          "   ",
          "    ",
          "     ",
          "      ",
          "       ",
          "        "
       };
    
    
    
       public static String convert(int number) {
    
          ArrayList<String> sNum = new ArrayList<String>();
    
          while ( number > 0 ) {
             int digit = number % spaceArray.length;
             number = Math.floor(number / 10);
             sNum.add(spaceArray[digit])
          }
    
          String octal = "";
          for(int ii = sNum.size() - 1; ii>=0; ii--) {
             String spaceDigit = sNum.get(ii);
             int digit = spaceDigit.length();
             octal += Integer.toString(digit);
          }
          return octal;
       }
    
    }
    

    ... and no, I didn't test it. This is off the top of my head so YMMV. Need a new numerical base? Change the array definition. Use a HashMap for Hexidecimal.

    --Zarf aka Foo

  • anonymous (unregistered)
                      /´¯/) 
                    ,/¯  / 
                   /    / 
             /´¯/'   '/´¯¯·¸ 
          /'/    /    /    /¨¨/¯\ 
         ('(    ´    ´     ¯ ;/'  ') 
          \                 '     / 
           '\'   \           _.·´ 
             \              ( 
               \             \ 
    
  • anonymous (unregistered)
                      /´¯/) 
                    ,/¯  / 
                   /    / 
             /´¯/'   '/´¯¯·¸ 
          /'/    /    /    /¨¨/¯\ 
         ('(    ´    ´     ¯ ;/'  ') 
          \                 '     / 
           '\'   \           _.·´ 
             \              ( 
               \             \ 
    
  • anonymous (unregistered)
     ___
    ,'_  "`-.        ,-'"`-.
    ('"/"-.   \    /  ,-,.  \
    `'    \  ,-'- /    /  `-'
          ,-'-.        /
       __ ("|")   f
      (_)`-"---.  |
       l   ---.      j
        `---'      ,'
            \     f
             )   l
          __f _Y
       ,'",-'"_" l
      (,,(,,,' ` Y
           |      l
           |      \,';,
           l    ,    Y, ;
           (`._(     ),'
            `.  `.  (
          ,--',--'   )
         (,,,(,,,---'
    

    captcha: howdy - the rabbit says 'HOWDY'!

  • David (unregistered)
    static char *sevenSpaces = "       ";
    char *pSpaceChar[8] = {
        eightSpaces + 7,
        eightSpaces + 6,
        eightSpaces + 5,
        eightSpaces + 4,
        eightSpaces + 3,
        eightSpaces + 2,
        eightSpaces + 1,
        eightSpaces
    };

Leave a comment on “Global Spaces”

Log In or post as a guest

Replying to comment #120957:

« Return to Article