Suppose I have a text file with potentially very long lines of text, for example
short
short
reeeeeeeeeeeeeeeeeeeeeeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaally loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooonnnnggg
short as well
short
I can write a simple program which reads this file:
program main
implicit none
integer, parameter :: BIG_NUMBER = 400
integer :: lun
character(len=BIG_NUMBER) :: line
integer :: istat
open(newunit = lun, file = 'myfile')
do
read (lun, '(A)', iostat = istat) line
if (istat /= 0) exit
end do
end program main
This only supports text files, where all lines are not longer than 400 characters. In C, pointers are used and a similar program would automatically support any text file.
How can I rewrite the sample program in such a way that it can read lines of all lengths?