Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!europa.chnt.gtegsc.com!gatech!howland.reston.ans.net!Germany.EU.net!Munich.Germany.EU.net!ecrc!news
From: joachim@ecrc.de (Joachim Schimpf)
Subject: Re: sscanf,sprintf in prolog
Message-ID: <D89Gs3.x8@ecrc.de>
Sender: news@ecrc.de
Reply-To: joachim@ecrc.de
Organization: European Computer-Industry Research Centre GmbH, Munich, Germany
References: <marianne.799892869@coral.cs.jcu.edu.au>
Date: Mon, 8 May 1995 13:14:26 GMT
Lines: 36

In article 799892869@coral.cs.jcu.edu.au, marianne@cs.jcu.edu.au (Marianne Brown) writes:
>
>I'm looking for a way to read from a string as opposed to from a stream -
>sort of a prolog equivalent to C's sscanf (and sprintf would be nice too).


There is no portable way of doing this. For ECLiPSe, the answer is:

Either term_string/2 (works both ways):

    term_string(Term, String)

Or using string I/O:

    sread(String, Term) :-
        open(String, string, Stream), read(Stream, Term), close(Stream).

    swrite(Term, String) :-
        open("", string, Stream), write(Stream, Term),
        current_stream(String, _, Stream), close(Stream).


[ This really is an FAQ! Would somebody care and collect
  the answers this time and put them in the FAQ? ]

-- Joachim

---------------------------------------------------------------------------
 ECLiPSe WWW pages:		http://www.ecrc.de/eclipse/eclipse.html
 ECLiPSe FTP site:		ftp.ecrc.de  (141.1.1.1)  /eclipse
 User group mailing list contributions:		eclipse_users@ecrc.de
 Orders and mailing list administration:	eclipse_request@ecrc.de
 ECLiPSe development team:			eclipse@ecrc.de
 Bug reports:					eclipse_bugs@ecrc.de


