0

在 Fortran 95 中编写一个非常简单的读取文件。该文件中只有三个数字,每次我运行代码时,.exe 文件都会显示“ error: attempt to read end-of-file at address”,任何线索为什么会一直发生这种情况?

代码是:

program readdata

implicit none

!Delcaration of variables

real :: x,y,z

!Main part

open (10, file='C:\Users\matth\OneDrive\Documents\Tutorialcode\array.txt',ACCESS='SEQUENTIAL', STATUS='OLD', FORM='FORMATTED')

read (10, *) x, y, z

print *,x,y,z

close (10)

end program readdata
4

1 回答 1

0

我已使用 GNU Fortran 将您的代码加载到我的 Eclipse IDE 中。

我确认代码可以编译,没有错误或警告,并且按照宣传的方式运行。

使用 array.txt 文件:

1.00, 2.00, 3.00

我得到输出:

1.00, 2.00, 3.00

使用空文件,我得到:

At line 13 of file ../readdata.f90 (unit = 10, file = 'C:\Users\franc\array.txt')
Fortran runtime error: End of file

Error termination. Backtrace:

Could not print backtrace: libbacktrace could not find executable to open
#0  0xffffffff
#1  0xffffffff
#2  0xffffffff
#3  0xffffffff
#4  0xffffffff
#5  0xffffffff
#6  0xffffffff
#7  0xffffffff
#8  0xffffffff
#9  0xffffffff
#10  0xffffffff
#11  0xffffffff
#12  0xffffffff
#13  0xffffffff
#14  0xffffffff

因此,我怀疑您的文件是否缺少某些值。

另请参阅:

Fortran 90 - 尝试读取文件末尾

于 2020-02-08T14:32:45.770 回答