Source Code for Print a "Box"

This is a discussion on Source Code for Print a "Box" within the C Programming forums, part of the General Programming Boards category; I think I got it...(Print a box using ASCII characters) But I wish to simplify it... any suggestions dudes ??? ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    Source Code for Print a "Box"

    I think I got it...(Print a box using ASCII characters)

    But I wish to simplify it... any suggestions dudes ???

    ----------------------------------------------------

    #include <stdio.h>

    #define UL 213 /*upper left*/
    #define LL 212 /*lower left*/
    #define UR 184 /*upper right*/
    #define LR 190 /*lower right*/
    #define HZ 205 /*horizontal line*/
    #define VR 179 /*vertical line*/

    main()
    {
    int x1, y1, x2, y2, i;

    clrscr();

    printf("Please define the proper coordinates of a 2-Dimensional window.\n");
    printf("\n\nFor the UPPER LEFT coordinates.\n");
    printf("\nInput the 1st x-coordinate(x1): ");
    scanf("%i", &x1);
    printf("\nInput the 1st y-coordinate(y1): ");
    scanf("%i", &y1);
    printf("\n\nFor the LOWER RIGHT coordinates.\n");
    printf("\nInput the 2nd x-coordinate(x2): ");
    scanf("%i", &x2);
    printf("\nInput the 2nd y-coordinate(y2): ");
    scanf("%i", &y2);

    clrscr();

    gotoxy(x1, y1);
    printf("%c", UL);

    gotoxy(x2, y2);
    printf("%c", LR);

    gotoxy(x1, y2);
    printf("%c", LL);

    gotoxy(x2, y1);
    printf("%c", UR);

    for(i=1; i<y2-y1; i++)
    {
    gotoxy(x1, y1+i);
    printf("%c", VR);
    }

    for(i=1; i<y2-y1; i++)
    {
    gotoxy(x2, y1+i);
    printf("%c", VR);
    }

    for(i=1; i<x2-x1; i++)
    {
    gotoxy(x1+i, y1);
    printf("%c", HZ);
    }

    for(i=1; i<x2-x1; i++)
    {
    gotoxy(x1+i, y2);
    printf("%c", HZ);
    }

    getch();
    }


    =====================

    Thanks !!

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    Oi !! Salem ... Thanks !!

    Thanks for your suggestions... I've taken full note of it !!

    Oh yes,.., I have tested my code.. and it works !!

    I would try yours and compile it... actually, we just finished a lecture on functions.. That's just GREAT !!

    I would like to ask you if you could explain (even just a little bit)
    those function lines (after #define VR 179 /*vertical line*/)..

    some footnotes on those 4 functions would help a lot !!
    I think you call those functions as:
    1. Corner
    2. h_line
    3. v_line
    4. box

    Thanks Dude !!

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,156

    Re: Source Code for Print a "Box"

    Originally posted by imbecile in C
    I think I got it...(Print a box using ASCII characters)

    But I wish to simplify it... any suggestions dudes ???
    Yeah, don't go character by character. The output device (screen) still operates on lines.

    Do a gotoxy() for the UL, output the entire line from UL thru UR without additional gotoxy()'s

    Continue for each line.

    If it's just a box, a loop for each intervening line would allow you to have only 3 print sections: top line, all middle lines, bottom lines.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How do you call another source code file?
    By nifear4 in forum C Programming
    Replies: 2
    Last Post: 10-28-2008, 12:16 PM
  2. 'Type' Error on Build of Officially Released Source Code
    By Jedi_Mediator in forum C++ Programming
    Replies: 5
    Last Post: 07-07-2008, 05:28 PM
  3. DxEngine source code
    By Sang-drax in forum Game Programming
    Replies: 5
    Last Post: 06-26-2003, 05:50 PM
  4. Lines from Unix's source code have been copied into the heart of Linux????
    By zahid in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 05-19-2003, 03:50 PM
  5. Source Code Beautifier
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-05-2002, 09:21 PM

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