Drawing a Box

This is a discussion on Drawing a Box within the C Programming forums, part of the General Programming Boards category; Hi Guys, I have got a quick question which i couldn't able to solve. Wanted to draw a square to ...

  1. #1
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682

    Drawing a Box

    Hi Guys,
    I have got a quick question which i couldn't able to solve. Wanted to draw a square to actually create a maze but i was stuck in between. Here is a simple code which i wrote

    Code:
    #include<stdio.h>
    
    
    void DrawABox()
    {
        printf(" --\n|  |\n --\n");
    }
    
    int main()
    {
        int i;
        
           for(i=0;i<6;i++)
                  DrawABox();
                                
        getchar();
        return 0;
    }
    
    /*My output
     --
    |  |
     --
     --
    |  |
     --
     --
    |  |
     --
     --
    |  |
     --
     --
    |  |
     --
     --
    |  |
     --
    */
    This code draws the box vertically. But i wanted horizontally like
    Code:
     --   --
    |  | |  |...
     --   --
    something like that. Is it possible. Does any one have any ideas.

    Thank you

    ssharish2005
    Last edited by ssharish2005; 09-28-2006 at 03:22 PM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,341
    char screen[25][80];

    Fill it up with whatever pattern of spaces and walls you like, then just print it out in the obvious manner.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Just tell DrawABox() how many boxes you want:
    Code:
    #include<stdio.h>
    
    
    void DrawABox(int howmany)
    {
        for(int i=0;i<howmany;i++){
            printf(" --  ");
        }
        printf("\n");
        for(int i=0;i<howmany;i++){
            printf("|  | ");
        }
        printf("\n");
        for(int i=0;i<howmany;i++){
            printf(" --  ");
        }
        printf("\n");
        return;
    }
    
    int main()
    {
        int i;
        
        DrawABox(6);
                                
        getchar();
        return 0;
    }
    And this will work even if you put many boxes, just goes to the next line:
    Code:
    #include<stdio.h>
    
    
    void DrawABox(int howmany)
    {
        int ar=0;
        for(int b=howmany;b>0;b-=15){
            if(b>15){
                ar=15;
            }
            else{
                ar=b;
            }
            for(int i=0;i<ar;i++){
                printf(" --  ");
            }
            printf("\n");
            for(int i=0;i<ar;i++){
                printf("|  | ");
            }
            printf("\n");
            for(int i=0;i<ar;i++){
                printf(" --  ");
            }
            printf("\n");
        }
        return;
    }
    
    int main()
    {
        int i;
        
    	DrawABox(100);
                                
        getchar();
        return 0;
    }
    Last edited by maxorator; 09-28-2006 at 03:06 PM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Hey Guys this is cool, thanks very much for the ideas. Salem and Maxorator that was really very helpful to me

    thanks again

    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 01:59 PM
  2. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  3. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 07:00 PM
  4. drawing a box
    By allthekandi in forum C++ Programming
    Replies: 4
    Last Post: 03-08-2003, 06:39 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

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