-
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
-
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.
-
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;
}
-
Hey Guys this is cool, thanks very much for the ideas. Salem and Maxorator that was really very helpful to me
thanks again
ssharish2005