以下fortran 90程序可以读取文本文件,然后在屏幕上将其打印出来。它具有一项附加功能,即当输出覆盖整个屏幕时,它将暂停并等待用户按Enter键继续。目前,我使用“暂停”来实现此功能。但我想知道直接输入Enter键的方式。请提供您的智慧。我很感激!
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
如果您在的输入列表中有一个项目read
,就像您在此处使用字符一样c
,则在为标准输入提供实际项目之前,不会继续执行。
您可以通过read(*,*)
不带输入的语句来实现所需的功能。这将只等待按键,放弃任何输入。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句