1 Attachment(s)
Create a rectangle with ASCII code.
This first block of code was originally taken right here from the forum.
Code:
#include <stdio.h>
int main(void)
{
int rows, columns, x, y;
while(1)
{
printf("Enter number of rows: ");
scanf("%d", &rows);
if ((rows < 3) || (rows > 20))
continue;
printf("Enter number of columns: ");
scanf("%d", &columns);
if ((columns < 3) || (columns > 20))
continue;
break;
}
for (x = 0; x < rows; x++)
{
for (y = 0; y < columns; y++)
{
if (x == 0 || x == rows - 1)
{
if (y == 0)
printf("+");
if (y == columns - 1)
printf("+\n");
else
printf("-");
}
else
{
if (y == 0)
printf("|");
if (y == columns - 1)
printf("|\n");
else
printf(" ");
}
}
}
return 0;
}
For my need I said thus:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int largura, altura, x, y;
//system("cls");
while(1)
{
printf("Digite a medida da largura: ");
scanf("%d", &largura);
if ((largura < 3) || (largura > 100))
continue;
printf("Digite a medida da altura: ");
scanf("%d", &altura);
if ((altura < 3) || (altura > 100))
continue;
break;
}
for (x = 0; x < altura; x++)
{
for (y = 0; y < largura; y++)
{
if (x == 0 || x == altura - 1)
{
if (y == 0)
//printf("+");
printf("%c", 218);
/*if (x != 0)
//printf("+");
printf("a");*/
if (y == largura - 1)
//printf("+\n");
printf("%c\n", 191);
else
//printf("-");
printf("%c", 196);
}
else
{
if (y == 0)
//printf("|");
printf("%c", 179);
if (y == largura - 1)
//printf("|\n");
printf("%c\n", 179);
else
printf(" ");
}
}
}
getchar();
return 0;
}
And I'm not getting the right characters on these two nodes as marked inside the white frames at the top of the print
Attachment 15667
Finally, I need to leave the rectangle completely closed as it should be, can any of your colleagues please help?
Thank you and God Bless ...