I am trying to print results of my sudoku solving program into terminal like this:
+-------+-------+-------+
| 1 2 3 | 4 5 6 | 7 8 9 |
| 1 2 3 | 4 5 6 | 7 8 9 |
| 1 2 3 | 4 5 6 | 7 8 9 |
+-------+-------+-------+
| 1 2 3 | 4 5 6 | 7 8 9 |
| 1 2 3 | 4 5 6 | 7 8 9 |
| 1 2 3 | 4 5 6 | 7 8 9 |
+-------+-------+-------+
| 1 2 3 | 4 5 6 | 7 8 9 |
| 1 2 3 | 4 5 6 | 7 8 9 |
| 1 2 3 | 4 5 6 | 7 8 9 |
+-------+-------+-------+
I store my solution in one dimensional array and I cannot find a way to print it. This is what I came up with so far:
printf("| %c %c %c | %c %c %c | %c %c %c |\n", test[0],test[1],test[2],test[3],test[4],test[5],test[6],test[7],test[8]);
I cannot use any cycles because I need to draw the "walls" around the numbers. Is there any better way to do it? And why does
char test[] = {'1','2','3','4','5','6','7','8','9'};
int i = 0;
printf("| %c %c %c | %c %c %c | %c %c %c |\n", test[i++],test[i++],test[i++],test[i++],test[i++],test[i++],test[i++],test[i++],test[i++]);
returns | 9 8 7 | 6 5 4 | 3 2 1 |
Thanks.
gccby reading the evaluation order. why do you say you can't use a loop? think it twice. that's not true.printf("| %c %c %c | %c %c %c | %c %c %c |\n", test[i++],test[i++],test[i++],test[i++],test[i++],test[i++],test[i++],test[i++],test[i++]);withprintf("| %c %c %c | %c %c %c | %c %c %c |\n", test[i],test[i+1],test[i+2],test[i+3],test[i+4],test[i+5],test[i+6],test[i+7],test[i+8]); i+=9;