-2

I have this "draw" at this moment:

What i have

I want to draw numbers in the top, like I did with the letters on left. Something like this:

What I want

How can I do that? This is my code at this moment:

void MostrarC1(int C1[][14])
{
    char arrLetras[] = { 'A', 'B', ' ', 'C', 'D' };
    // Ciclo linhas
    printf("\n");
    for (int lin = 0; lin <= 4; lin++)
    {
        printf("%c ", arrLetras[lin]);
        fflush(stdout);

        // Ciclo colunas
        for (int col = 0; col <= 13; col++)
        {

            // lugares
            if (lin != 2)
            {
                C1[lin][col] = 0;
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
                printf("  ");
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
                printf("|");
            }
            // corredor
            else
            {
                C1[lin][col] = 0;
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_BLUE);
                printf("   ");
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
            }
        }
        printf("\n");
    }
    printf("\n\n");
}
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
ItzMeN0n
  • 3
  • 1
  • 5

1 Answers1

0

I suggest you use a library like ncurses(PDCurses in windows) to display stuff wherever you want.

If you wanna continue using the standard output, you need to print the col + 1 inside the for that iterate columns but checking if it is in the first line. The main problem I foresee is the correct spacing between numbers on the way you should display them because you need to print numbers with same spacing so it fits correctly, to solve it, I suggest you to use left padding of the printf function:

int value1 = 2;
int value2 = 12;
printf(%02d, value1) // output is 02
printf(%02d, value2) // output is 12

OBS: check this link for other leading options of the printf.

Community
  • 1
  • 1
Lucas Mota
  • 188
  • 2
  • 9