module link_module type link real :: n type (link), pointer :: next end type link end module link_module program ch2202_1 use link_module implicit none type (link), pointer :: root, current integer :: i = 0 integer :: error = 0 integer :: io_stat_number = 0 integer :: blank_lines = 0 real, allocatable, dimension (:) :: x allocate (root) print *, ' type in some numbers' read (unit=*,fmt=*,iostat=io_stat_number) root%n if (io_stat_number>0) then error = error + 1 else if (io_stat_number==-1) then nullify (root%next) else if (io_stat_number==-2) then blank_lines = blank_lines + 1 else i = i + 1 allocate (root%next) end if current => root do while (associated(current%next)) current => current%next read (unit=*,fmt=*,iostat=io_stat_number) current%n if (io_stat_number>0) then error = error + 1 else if (io_stat_number==-1) then nullify (current%next) else if (io_stat_number==-2) then blank_lines = blank_lines + 1 else i = i + 1 allocate (current%next) end if end do print *, i, ' items read' print *, blank_lines, ' blank lines' print *, error, ' items in error' allocate (x(1:i)) i = 1 current => root do while (associated(current%next)) x(i) = current%n i = i + 1 print *, current%n current => current%next end do print *, x end program ch2202_1