How to resolve the algorithm Input loop step by step in the Fortran programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Input loop step by step in the Fortran programming language

Table of Contents

Problem Statement

Read from a text stream either word-by-word or line-by-line until the stream runs out of data. The stream will have an unknown amount of data on it.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Input loop step by step in the Fortran programming language

Source code in the fortran programming language

program BasicInputLoop

  implicit none

  integer, parameter        :: in = 50, &
                               linelen = 1000
  integer                   :: ecode
  character(len=linelen)    :: l

  open(in, file="afile.txt", action="read", status="old", iostat=ecode)
  if ( ecode == 0 ) then
     do
        read(in, fmt="(A)", iostat=ecode) l
        if ( ecode /= 0 ) exit
        write(*,*) trim(l)
     end do
     close(in)
  end if

end program BasicInputLoop


  

You may also check:How to resolve the algorithm Knapsack problem/Unbounded step by step in the Java programming language
You may also check:How to resolve the algorithm Hostname step by step in the REXX programming language
You may also check:How to resolve the algorithm Inheritance/Multiple step by step in the Tcl programming language
You may also check:How to resolve the algorithm Permutations/Rank of a permutation step by step in the C programming language
You may also check:How to resolve the algorithm Averages/Arithmetic mean step by step in the ECL programming language