Article View: pl.comp.lang.funkcyjne
Article #915Re: Dlaczego to nie dziala?
From: Tomasz bla Fortuna
Date: Tue, 22 May 2007 17:37
Date: Tue, 22 May 2007 17:37
43 lines
2070 bytes
2070 bytes
> > > program ma zliczać ile razy w zadanym pliku wystąpił dany wyraz.
> > > problem w tym, że za bardzo nie chce działać...
>
> npisałem wcześniej, że ma zliczać wystąpienia zadanego wyrazu w
> podanym pliku. no wiem że trochę brakuje, ale nie mam pomysłu na to
> jakoś. czekam na olśnienie;)
Trzeba było napisać... ;p "Zróbcie za mnie moje zadanie domowe".
(* Wczytuje wyraz *)
let rec readWord channel s =
match input_char channel with
| ' ' | '\t' | '\n' | '\r' -> s
| ch -> readWord channel (s ^ (Char.escaped ch))
;;
(* Zlicza wyrazy... *)
let rec count input word cnt =
try
let current = readWord input "" in
if current = word then
count input word (cnt+1)
else
count input word cnt
with End_of_file -> cnt
;;
(* Wyświetla wynik, inicjalizuje plik... *)
let main filename word =
let file = open_in filename in
Printf.printf "%d\n" (count file word 1)
;;
main "counter.ml" "current";;
Nie jestem z tego kodu do końca zadowolony. Ale na zadanie domowe, masz
zrozumieć go. ;P
Pozdrawiam.
--
Tomasz bla Fortuna
jid: bla(at)af.gliwice.pl
pgp: 0x90746E79 @ pgp.mit.edu
Technical Details
Message-ID:
<20070522193752.7600166b@Vorago>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!newsfeed.silweb.pl!polsl.pl!not-for-mailReferences:
<1179785216.063894.71460@36g2000prm.googlegroups.com> <20070522012726.0c337e11@Vorago> <1179842560.748271.157590@u36g2000prd.googlegroups.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!newsfeed.silweb.pl!polsl.pl!not-for-mail From: Tomasz bla Fortuna <bla@thera.be> Newsgroups: pl.comp.lang.funkcyjne Subject: Re: Dlaczego to nie dziala? Date: Tue, 22 May 2007 19:37:52 +0200 Organization: Politechnika Slaska, Gliwice Lines: 61 Message-ID: <20070522193752.7600166b@Vorago> References: <1179785216.063894.71460@36g2000prm.googlegroups.com> <20070522012726.0c337e11@Vorago> <1179842560.748271.157590@u36g2000prd.googlegroups.com> NNTP-Posting-Host: afdns.sownet.pl Mime-Version: 1.0 X-Trace: polsl.pl 1179855414 9168 195.82.188.30 (22 May 2007 17:36:54 GMT) X-Complaints-To: news@polsl.pl NNTP-Posting-Date: Tue, 22 May 2007 17:36:54 +0000 (UTC) X-Newsreader: Claws Mail 2.9.1 (GTK+ 2.10.12; x86_64-pc-linux-gnu) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit