getc()とputc()
2014-09-23


c putc.for (simple version) -- put sharacter on standard output subroutine putc(c) integer*1 c integer*1 buf(80) ! MAXCARD(80) integer i,lastc data lastc/0/ if ((lastc .ge. 80) .or. (c .eq. 10)) then ! MAXCARD(80) NEWLINE(10) i = lastc + 1 while (i .le. 80) do ! MAXCARD(80) buf(i) = 32 ! BLANK(32) i = i + 1 end while write(6,100) (buf(i),i=1,80) ! MAXCARD(80) 100 format(80a1) ! MAXCARD(80) lastc = 0 endif if (c .ne. 10) then ! NEWLINE(10) lastc = lastc + 1 buf(lastc) = c endif return end

一行80文字にするために、空白文字を詰め合わせています。これでは、元の空白文字なのか、 詰め物か判別できませんし、固定長レコードにする、意味がWindowsにはありません。 行末の無駄な空白文字を書き出さないよう、lastc文字分しか書き出さないように変更しました。

c putc2.for (extended version 1) -- put sharacter on standard output
      subroutine putc(c)
      integer*1 c

      integer*1 buf(80) ! MAXCARD(80)
      integer i,lastc
      data lastc/0/

      if ((lastc .ge. 80) .or. (c .eq. 10)) then ! MAXCARD(80) NEWLINE(10)
          write(6,100) (buf(i),i=1,lastc)
  100     format(80a1)                     ! MAXCARD(80)
          lastc = 0
      endif
      if (c .ne. 10) then                  ! NEWLINE(10)
          lastc = lastc + 1
          buf(lastc) = c
      endif
      return
      end

戻る
[コンピューター]
[RATFOR]

コメント(全50件)
※コメントの受付件数を超えているため、この記事にコメントすることができません。


記事を書く
powered by ASAHIネット