users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: read/2 problem in gprolog-1.2.16 with SuSE 8.1


From: Detlef Sax
Subject: RE: read/2 problem in gprolog-1.2.16 with SuSE 8.1
Date: Mon, 14 Oct 2002 15:39:11 +0200 (CEST)

On 14-Oct-2002 address@hidden wrote:
> In-Reply-To: <address@hidden>
> 
>> Does the file 'test.txt' contain valid prolog syntax ?
> The answer is: No. The content is: test123
> 
> My intension is simply to read a plain ASCII text, so that
> read(F,R) will bee unified with R = 'test123'.
> How can I do that ?
> Regards,
> Roland Hanauer

Hi Roland,
to read a simple text file into a list you can use a construction
like this:

% open.pl
% GPL, what else? 2002 sax
io(List) :- 
                open('zeichen.txt', read, Stream),
                add_stream_alias(Stream, ali),
                chars_from_stream(List).
                
chars_from_stream(_) :-
                at_end_of_stream(ali),
                close(ali).
chars_from_stream([Char| Chars]) :-
                get_my_byte(Char),
                chars_from_stream(Chars).

get_my_byte(C) :-
        get_char(ali, C).
%        get_code(ali, C).
% EOF


HTH

Regards
Detlef

-- 
Ihr tägliches Horoskop von Meisterseher noart:
http://www.noart.de/new.html#horoskop




reply via email to

[Prev in Thread] Current Thread [Next in Thread]