I've a question about Fortran 77 and I've not been able to find a solution.
I'm trying to store an array of strings defined as the following:
character matname(255)*255
Which is an array of 255 strings of length 255.
Later I read the list of names from a file and I set the content of the array like this:
matname(matcount) = mname
EDIT: Actually mname
value is hardcoded as mname = 'AIR'
of type character*255
, it is a parameter of a function matadd()
which executes the previous line. But this is only for testing, in the future it will be read from a file.
Later on I want to print it with:
write(*,*) matname(matidx)
But it seems to print all the 255 characters, it prints the string I assigned and a lot of garbage.
- So that is my question, how can I know the length of the string stored?
- Should I have another array with all the lengths?
- And how can I know the length of the string read?
Thanks.
character mname*(*)
. Before, the end of that variable was random garbage, now it is padded with spaces. Thanks for the explanation, was very clarifying. Also I didn't know about the * notation. – Ohaus