! Copyright (c) 1994, 1996 Unicomp, Inc.
!
! Developed at Unicomp, Inc.
!
! Permission to use, copy, modify, and distribute this
! software is freely granted, provided that this notice 
! is preserved.

program char_count

   ! These two values are processor dependent.
   integer, parameter :: end_of_file = -1
   integer, parameter :: end_of_record = -2

   character (len = 1) :: c
   integer :: kount, ios

   kount = 0
   print *, "Enter as many characters as you want"
   print *, "on as many lines as you want."
   print *, "Enter a Q or an End of File to stop"

   do
      read (unit=*, fmt="(a)", advance = "no", iostat = ios) c
      if (ios == end_of_record) then
         cycle
      else if (ios == end_of_file .or. c == "Q") then
         exit
      else
         kount = kount + 1
      end if
   end do

   print *, "The number of characters in the file is", &
            kount

end program char_count
