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 !!
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 !!
Re: Source Code for Print a "Box"
Quote:
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.