Fortran

Guide To Learn

Custom Input/Output

This example demonstrates custom input and output routines.

fortranCopy codeprogram custom_io
    implicit none
    integer :: i
    character(len=100) :: line

    ! Write to file
    open(unit=10, file='output.txt', status='replace')
    do i = 1, 5
        write(10, '(A, I3)') 'Line number: ', i
    end do
    close(10)

    ! Read from file
    open(unit=20, file='output.txt', status='old')
    print *, 'Reading from file:'
    do
        read(20, '(A)', iostat=i) line
        if (i /= 0) exit
        print *, trim(line)
    end do
    close(20)
end program custom_io
Custom Input/Output

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top