0

I have this method that when called:

- (void)showContent
{
NSLog(@" 0  1  2  3  4  5  6");
for (int j = 0; j < rows; j++) {
    for (int k = 0; k < columns; k++) {
        MDLog(@"[%c]", board[j][k]);
    }
    NSLog(@"");
}
NSLog(@"---------------------------------------------------");
}

That's supposed to create an empty 6 x 7 grid (for a game of Connect Four) that looks like this:

0  1  2  3  4  5  6

[ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ]

[ ][ ][ ][ ][ ][ ][ ]

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

However, the Xcode console doesn't print it that way at all. It displays each column vertically on top of one another. Other useful info is I have

int rows; // initializes to be 6
int columns; // initializes to be 7
char board[6][7];

Xcode prints it this way:

 0  1  2  3  4  5  6

[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]

[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]

[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]

[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]

[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]

[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]

---------------------------------------------------
JJJJMo
  • 1
  • 1

1 Answers1

0

You could concatenate the string for each line and print it all at once. Alternatively you could use printf(). printf() does not add a newline so it would create the desired outcome.

- (void)showContent
{
    NSLog(@" 0  1  2  3  4  5  6");
    for (int j = 0; j < 6; j++) {
        for (int k = 0; k < 7; k++) {
            printf("[ ]");
        }
        printf("\n");
    }
    NSLog(@"---------------------------------------------------");

}

bradkratky
  • 1,577
  • 1
  • 14
  • 28