我需要編寫一個可讀取並打印.dat文件的Fortran程序。使用FORTRAN讀取並打印
(一個文件homework_6.dat包含書籍記錄:名稱(最多25個字符),發佈年份(4位整數),價格(6位數字實數),ISBN(13位整數)。文件(homework_6.dat),並以下列格式打印出來(在屏幕上或到另一個文件)的詳細信息:
Publish
Name Year ($) ISBN
------------------------- ---- ------ -------------
Principles of Combustion 2005 107.61 9780471046899
An Introduction to Comb 2011 193.99 9780073380193
Guide to Fortran 2009 71.95 9781848825420
Modern Fortran Explain 2011 100.00 9780199601417
Introduction to Program 2012 200.00 9780857292322)
這裏我寫的東西
program dat
implicit none
character (len=25) :: Name
integer :: i, publish_year, ISBN
real :: price
open(unit=7, file="homework_6.dat", status="old", action="readwrite")
do i=1, 10
read (unit=7,fmt="(a25,i4,f3.2,i13)") Name, publish_year, price, ISBN
write (unit=7,fmt="(a25,i4,f3.2,i13)") Name, publish_year, price, ISBN
end do
close(unit=7)
end program dat
但Fortran語言說,有是一個錯誤第8行
,我不知道該怎麼辦:(
索尼婭(ITU)
- 編輯 -
於是,我寫了一個程序,但執行後,我仍然有錯誤
program dat
implicit none
character (len=25) :: Name
character (len=13) :: ISBN
integer :: i, publish_year
real :: price
open(unit=10, file="homework_6.dat", status="old", action="readwrite")
open(unit=11, file="output_hw6.dat")
!Comment: these below 3 lines are for skipping 3 heading your input
read(10,*)
read(10,*)
read(10,*)
do i=1, 10
read (10,*) Name, publish_year, price, ISBN
write (11,1) Name, publish_year, price, ISBN
1 format(a25,2x,i4,2x,f3.2,2x,a13)
end do
close(unit=10)
end program dat
我在線路錯誤14. ERROR 52,在字段無效字符 DAT - 在文件homework.f95在管線14 [+ 01b3]
您應該發佈您看到的錯誤消息。 –
什麼錯誤?運行時還是編譯時?寫在這裏。 –
您需要執行三次讀取才能跳過文件中的三個標題行。 –