How to read "enter" key in fortran

The following fortran 90 program can read in a text file and then print it on the screen. This has an added feature that when the output covers the entire screen, it pauses and waits for the user to press the enter key to continue. I am currently using PAUSE to implement this feature. But I would like to know a direct way of reading in the enter key. Please offer your wisdom. I appreciate it!

program ex0905
  implicit none
  character(len=79)  :: filename
  character(len=79)  :: buffer
  integer, parameter :: fileid = 10
  integer :: status = 0,count=0
  logical alive
  character(len=1) :: c

  write(*,*) "Filename:"
  read (*,"(A79)") filename
  inquire( file=filename, exist=alive)

  if ( alive ) then
     open(unit=fileid, file=filename, &
         access="sequential", status="old")
  do while(.true.)
     read(unit=fileid, fmt="(A79)", iostat=status ) buffer
     if ( status/=0 ) exit
     !write(*,"(A79)") buffer
     count = count+1
     if (count<24) then
        write(*,"(A79)") buffer
     else
       !write(*,*) "Please type Enter to continue: "
       pause
       count=0
       !read(*,"(A1)") c
       !if (c==char(13)) then
       !   write(*,"(A79)") buffer
       !else
       !   write(*,*) "This is not the 'Enter' key!!"
       !   exit
       !end if
     end if

   end do
  else
    write(*,*) TRIM(filename)," doesn't exist."
  end if

 stop  
end
+4
source share
1 answer

read, , c, , .

, , read(*,*) . , .

+3

Source: https://habr.com/ru/post/1546193/


All Articles