Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two dimensional character array 1

Status
Not open for further replies.

Levay87

Programmer
Jun 12, 2016
6
DE
Hello,
I would like to define a two dimensional character array.
My program does not run! Please help me.

program exercise10
implicit none



character(1), dimension(3,3)::arr1=(/(/"a","b","c"/),(/"a","b","c"/),(/"a","b","c"/)/)




write(*,*) "Exersice10: ", arr1

end program exercise10

 
A few ways around this but you cannot do it in initialization.
Code:
character(1), dimension(3,3)::arr1

arr1 =reshape((/"a","b","c", "a","b","c", "a","b","c"/), shape(arr1))

! arr =reshape((/"a","b","c", "a","b","c", "a","b","c"/), (/ 3,3 /))
! arr =reshape((/"a","b","c", "a","b","c", "a","b","c"/), (/ size(arr1,2), size(arr1,1) /))
 
Try a 2d array where the two dimensions are of different sizes and watch what happens: note that the higher dimension changes fastest.
 
Yes, you can do it right during initialization

Code:
program arr2d2
    character(len=1), dimension(3,3) :: arr1 = reshape( (/'a','b','c','a','b','c','a','b','c'/), shape(arr1) )
    write(*,'( 3(1x,a1) )') arr1
end program arr2d2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top