如何修复 Fortran 程序的这个错误?

问题描述 投票:0回答:0

我的程序出现这个错误

{ main.f95:30:18:
   30 |             name,':',  student_id,':',  gpa ':',address ':'
      |                  1
Error: Expecting variable in READ statement at (1)}




program student_parser

    implicit none
    
    integer, parameter :: num_students = 4
    integer :: i, count = 0
    real :: gpa
    character(100) :: line, name, address
    integer :: student_id
    type student
        character(50) :: name
        integer :: student_id
        character(100) :: address
        real :: gpa
    end type student
    
    type(student) :: students(num_students)

    open(10, file='StudentInfo.txt', status='old')
    do i = 1, num_students
        read(10, '(A)', iostat=count) line
        read(line, '(A, A, I10, A, F5.2, A)', iostat=count) &
            name,':',  student_id,':',  gpa ':',address ':'
        if (gpa > 4.0) then
            students(i)%name = trim(name)
            students(i)%student_id = student_id
            students(i)%address = trim(address)
            students(i)%gpa = gpa
            write(*, '("Name",A, ", ","Address:", A)', advance='yes') students(i)%name, students(i)%address
        endif
    end do
    close(10)
    
end program student_parser
fortran computer-science
© www.soinside.com 2019 - 2024. All rights reserved.