chap06/kadai6.f90

サンプルコードのダウンロード

 1program answer
 2  implicit none
 3
 4  integer, parameter :: max_line = 256
 5  integer :: ios, nline, count
 6  character(max_line) :: line
 7
 8  count = 0
 9  nline = 1
10
11  read(*, fmt='(a)', iostat=ios) line
12
13  do while(ios == 0)
14    ! remove whitespace
15    line = adjustl(line)
16
17    ! count only if the line is not blank or comment
18    if(line /= '' .and. line(1:1) /= '!') then
19      count = count + 1
20    endif
21
22    ! read next line
23    read(*, fmt='(a)', iostat=ios) line
24    nline = nline + 1
25  enddo
26
27  write(*, *) 'Number of lines with valid fortran statement : ', count
28
29  stop
30endprogram answer