Any way to make shorter???

This is a discussion on Any way to make shorter??? within the C Programming forums, part of the General Programming Boards category; Hey, I am making this DOS maze game and to make my levels i have to use %c and the ...

  1. #1
    Unregistered
    Guest

    Question Any way to make shorter???

    Hey, I am making this DOS maze game and to make my levels i have to use %c and the binary code for the two lines thing (eg 200, 205, 204 ect). How can I make this code shorter?

    printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c%c\
    %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c %c%c%c%c%c\
    %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c"
    ,V,S,S,S,V,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,BL,RIS,S, S,S,V,S,S,S,V
    ,S,S,S,V,BP,S,V,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S, S,S,S,S,S,S
    ,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,S,V);

    V, S, BP, BL RIS are #defines to the binarys, that i put in a Header file.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    While I fail to understand what is all that for, I suggest using a structuce/array to store those values. And then print 'em in a loop... ?
    kooma - t.h@iki.fi

  3. #3
    Unregistered
    Guest
    Binary? When you say "200, 205, 204", I assume that you mean you have defined these "V, S, BP"s using the integer codes for the ASCII characters you wish to see printed.

    In that case, and if the code below is the extent of the problem, then I would suggest doing it like this:

    Code:
         char                        // instead of #define's
            V = (char)200,
            S = (char)205,
            BP = (char)204;
    
        char szMazeString[] =    // make your maze an array of chars
        { V, S, BP, '\n',        // \n for newline at the end of each row
           V, V, V, '\n',
           BP, S, BP, '\n',
           0 };                    // don't forget to with a NULL character (0)
    
        printf("%s", MazeString); // print it as a string with just one call to printf
    Regardless of how printf(...) functions internally, it seems to me that this should be significantly faster.

  4. #4
    Unregistered
    Guest
    Hrm, a small correction:

    either use "const char" instead of "char", or go back to using #define and, for example, #define V (char)200, etc...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I improve this code or make it shorter?
    By abh!shek in forum C++ Programming
    Replies: 27
    Last Post: 01-13-2008, 01:07 PM
  2. "Cannot make pipe"
    By crepincdotcom in forum C Programming
    Replies: 5
    Last Post: 08-16-2004, 01:43 PM
  3. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 05:19 AM
  4. make all rule
    By duffy in forum C Programming
    Replies: 9
    Last Post: 09-11-2003, 02:05 PM
  5. Replies: 6
    Last Post: 04-20-2002, 07:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21