You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 208 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
I am trying to read in a whole file into a string using the following predicate.
Note that I have to remove 235 (probably since there are 235 ^M in the file),
otherwise I get an end-of-file error. channel_length is doing correctly and
returning 24961.
let read_all2 filename =
let ic = open_in filename in
let size = in_channel_length ic in
let buf = String.create size in
let _ = really_input ic buf 0 (size-235) in
close_in ic;
buf
;;
I am trying to read in a whole file into a string using the following predicate.
You mean function not predicate, do you ?
Note that I have to remove 235 (probably since there are 235 ^M in the file),
otherwise I get an end-of-file error. channel_length is doing correctly and
returning 24961.
let read_all2 filename =
let ic = open_in filename in
let size = in_channel_length ic in
let buf = String.create size in
let _ = really_input ic buf 0 (size-235) in
close_in ic;
buf
;;
Your problem is that you opened your file in text mode, instead of
binary mode. Thus end-of-line markers are omitted from the input
count.
You can use open_in_bin if you want to have the exact count of the
characters written into the file. However this is not portable, since
end-of-line markers are not the same under Unix, MacOS and Windows...
This suggest to add a function into the standard library to read a
file into a string (or more generally a buffer). Thus, I would suggest
the names buffer_of_file and string_of_file for such functions ...
Original bug ID: 208
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
Full_Name: mattias waldau
Version: 3.00
OS: windows 2000
Submission from: dialup-31.abc.se (195.17.73.31)
Using O'Caml 3.00, Windows 2000.
I am trying to read in a whole file into a string using the following predicate.
Note that I have to remove 235 (probably since there are 235 ^M in the file),
otherwise I get an end-of-file error. channel_length is doing correctly and
returning 24961.
(* 649 1800 24961 c:/stock/www.dljdirect.com/20000722151743.html
*)
let read_all2 filename =
let ic = open_in filename in
let size = in_channel_length ic in
let buf = String.create size in
let _ = really_input ic buf 0 (size-235) in
close_in ic;
buf
;;
read_all2 "c:/stock/www.dljdirect.com/20000722151743.html";;
P.s. How should I attach the file?
Mattias Waldau, CTO
Tacton AB, Saltmätargatan 7, 11359 Stockholm
Mobile +46 70 549 11 12
http://www.tacton.com mailto:mattias.waldau@tacton.com
The text was updated successfully, but these errors were encountered: