If you want the program to be a character mode application, you have to live with the limitations of the language (only 1-byte characters), the characters available ('║' is not available unless you use Unicode or the old IBM PC extended characters), or be ready to create and use a lot of tricks to get around these limitations.
If you are willing to use '|' and '¦' in place of '║' and '|' , the following code may satisfy you.
program t
implicit none
integer :: cell(1:9,1:9)
integer i,j,k
character(len=1) :: string_cell(1:9,1:9)
character(len=1) :: sbar = char(124), bbar = char(166)
character(len=45) :: fmt = '(3(A1,1x,A1,1x,' ',1x,A1,1x,' ',1x,A1,1x),A1)'
character(len=37) :: eql = '====================================='
character(len=37) :: mil = '-------------------------------------'
cell = reshape((/0,0,0,0,0,0,0,0,0, &
0,0,0,0,1,6,2,0,5, &
0,0,8,0,0,0,0,7,6, &
0,0,0,0,6,0,0,3,0, &
0,1,0,7,8,0,0,0,0, &
0,6,0,0,0,4,0,2,8, &
0,5,0,0,0,0,0,0,0, &
0,0,1,4,0,7,0,6,2, &
0,8,6,0,0,3,0,4,9/),shape(cell))
do j = 1,2
i=index(fmt,' ')
fmt(i:i) = bbar
end do
! Copy current integer array cell to 'equivalent' string_cell array, replacing 0 with ' '
where (cell == 0)
string_cell = ' '
else where
string_cell = char(cell+48)
end where
print '(A)',eql
do k = 1,9
print fmt,(sbar,(string_cell(i,k),i=j*3-2,j*3),j=1,3),sbar
if (mod(k,3) == 0) then
print '(A)',eql
else
print '(A)',mil
endif
end do
end program t
The output, viewed using an editor such as Plato:
=====================================
| ¦ ¦ | ¦ ¦ | ¦ ¦ |
-------------------------------------
| ¦ ¦ | ¦ 1 ¦ 6 | 2 ¦ ¦ 5 |
-------------------------------------
| ¦ ¦ 8 | ¦ ¦ | ¦ 7 ¦ 6 |
=====================================
| ¦ ¦ | ¦ 6 ¦ | ¦ 3 ¦ |
-------------------------------------
| ¦ 1 ¦ | 7 ¦ 8 ¦ | ¦ ¦ |
-------------------------------------
| ¦ 6 ¦ | ¦ ¦ 4 | ¦ 2 ¦ 8 |
=====================================
| ¦ 5 ¦ | ¦ ¦ | ¦ ¦ |
-------------------------------------
| ¦ ¦ 1 | 4 ¦ ¦ 7 | ¦ 6 ¦ 2 |
-------------------------------------
| ¦ 8 ¦ 6 | ¦ ¦ 3 | ¦ 4 ¦ 9 |
=====================================
The '¦' will probably not be displayed properly in the console unless you have set CMD.EXE to use an appropriate font.
Side Note:
In my 'learning fortran' book,it tells me the function CHAR(I), should convert an integer (I) to a character string...but that didn't seem to work.
That is not quite correct. CHAR(I) returns the character whose ASCII sequence number (starting with 0) equals the value of the argument, I. The character '0' has ASCII sequence number Z'30', or 48 in decimal. That's the reason for the offset adjustment +48 that you can see in the code.