我正在尝试从输入中读取单词并将每个单词存储在列表中。然后我想计算每个单词中的元音并将计数写入文件。
这是我到目前为止所做的:
readWord(InStream,W) :- get0(InStream,Char),
checkCharAndReadRest(Char,Chars,InStream)
% ,program(Chars),
,checkChars(Chars) ,
atom_chars(W,Chars).
%checkChars(Chars):- member([97,101,105,111,117] , Chars).
checkChars(Chars):- member(97, Chars).
checkCharAndReadRest(10,[],_) :- !. % Return
checkCharAndReadRest(32,[],_) :- !. % Space
checkCharAndReadRest(-1,[],_) :- !. % End of Stream
checkCharAndReadRest(end_of_file,[],_) :- !.
checkCharAndReadRest(Char,[Char|Chars],InStream) :-
get0(InStream,NextChar),
checkCharAndReadRest(NextChar,Chars,InStream).
writeWord(end_of_file).
writeWord(X) :- write(X),nl.
readFile :-
open('c:/sample.txt', read, In),
repeat,
readWord(In,W),
writeWord(W),
W == end_of_file,
!,
close(In).
member(X, [ _ | Z]):-member(X, Z).
member(X, [X | _ ]):-increment(0,N).
increment(N0,N):- N is N0+1,write(N).
%program(Chars) :-
%open('e:/outputfile.txt',write, Stream),
%write(Stream,X),
%close(Stream).
这些单词完美地存储在列表中,但我不知道每次如何计算它们 并将计数发送到文件。