(* Returns a char from stdin, or ^D if EOF *) let get_char () = try (input_char stdin) (* read a character *) with End_of_file -> '\004' (* assume ^D marks EOF *) ;; (* Returns # chars read (including '\n') *) let rec count_chars () = let c = (get_char ()) in (* get a character *) if (c = '\004') then 0 (* if EOF then 0 chars *) else 1+count_chars() (* else read more chars *) ;; print_int ( count_chars () ) ; print_endline "" ;;