Fortran 文件 的问题 10
我编了一个输入学生学号,姓名,性别,电话号码的文件。Moduletypedeftypestudentinteger*4numbercharacter*8namechara...
我编了一个输入学生学号,姓名,性别,电话号码的文件。
Module typedef
type student
integer*4 number
character*8 name
character*2 sex
integer*4 phone
end type
end module
program main
use typedef
implicit none
integer,parameter::fileid=10
character(len=20)::filename="contaction.txt"
type(student),allocatable::s(:)
integer::i
integer*8 students
write(*,*)"Please input the amount of students."
read(*,*) students
allocate(s(students),stat=i)
if(i/=0)then
write(*,*) "Failed."
stop
end if
open(fileid,file=filename,access="direct",form="formatted",recl=79,status="replace")
do i=1,students
write(*,"('Please input N0.',I2,'student''s 学号,姓名,性别,电话号码.')") i
read(*,*) s(i)%number,s(i)%name,s(i)%sex,s(i)%phone
write(fileid,"(I5,1X,A8,1X,A2,1X,I7)") s(i)%number,s(i)%name,s(i)%sex,s(i)%phone
end do
close(fileid,status='keep')
stop
end
每次运行,输入一个学生的信息之后,就弹出错误信息。
forrtl:severe<259>:sequential-access I/O to unit open for direct access,unit 10,file C:\.......
愿大神帮忙看看。谢谢了啊!! 展开
Module typedef
type student
integer*4 number
character*8 name
character*2 sex
integer*4 phone
end type
end module
program main
use typedef
implicit none
integer,parameter::fileid=10
character(len=20)::filename="contaction.txt"
type(student),allocatable::s(:)
integer::i
integer*8 students
write(*,*)"Please input the amount of students."
read(*,*) students
allocate(s(students),stat=i)
if(i/=0)then
write(*,*) "Failed."
stop
end if
open(fileid,file=filename,access="direct",form="formatted",recl=79,status="replace")
do i=1,students
write(*,"('Please input N0.',I2,'student''s 学号,姓名,性别,电话号码.')") i
read(*,*) s(i)%number,s(i)%name,s(i)%sex,s(i)%phone
write(fileid,"(I5,1X,A8,1X,A2,1X,I7)") s(i)%number,s(i)%name,s(i)%sex,s(i)%phone
end do
close(fileid,status='keep')
stop
end
每次运行,输入一个学生的信息之后,就弹出错误信息。
forrtl:severe<259>:sequential-access I/O to unit open for direct access,unit 10,file C:\.......
愿大神帮忙看看。谢谢了啊!! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询